Skip to content

Commit

Permalink
test(complete): Add empty subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 24, 2024
1 parent 87e28c2 commit 8e246ef
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 26 deletions.
3 changes: 3 additions & 0 deletions clap_complete/examples/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ fn cli() -> clap::Command {
.value_parser(clap::value_parser!(Shell))
.help("generate")])
.subcommands([
clap::Command::new("empty")
.disable_help_subcommand(true)
.disable_help_flag(true),
clap::Command::new("global")
.version("3.0")
.propagate_version(true)
Expand Down
38 changes: 36 additions & 2 deletions clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ _exhaustive() {
exhaustive,alias)
cmd="exhaustive__alias"
;;
exhaustive,empty)
cmd="exhaustive__empty"
;;
exhaustive,global)
cmd="exhaustive__global"
;;
Expand Down Expand Up @@ -80,6 +83,9 @@ _exhaustive() {
exhaustive__help,alias)
cmd="exhaustive__help__alias"
;;
exhaustive__help,empty)
cmd="exhaustive__help__empty"
;;
exhaustive__help,global)
cmd="exhaustive__help__global"
;;
Expand Down Expand Up @@ -210,7 +216,7 @@ _exhaustive() {

case "${cmd}" in
exhaustive)
opts="-h --generate --help global action quote value pacman last alias hint help"
opts="-h --generate --help empty global action quote value pacman last alias hint help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -279,6 +285,20 @@ _exhaustive() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__empty)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__global)
opts="-h -V --global --help --version one two help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
Expand Down Expand Up @@ -448,7 +468,7 @@ _exhaustive() {
return 0
;;
exhaustive__help)
opts="global action quote value pacman last alias hint help"
opts="empty global action quote value pacman last alias hint help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -489,6 +509,20 @@ _exhaustive() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__help__empty)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__help__global)
opts="one two"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand --generate 'generate'
cand -h 'Print help'
cand --help 'Print help'
cand empty 'empty'
cand global 'global'
cand action 'action'
cand quote 'quote'
Expand All @@ -33,6 +34,8 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand hint 'hint'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'exhaustive;empty'= {
}
&'exhaustive;global'= {
cand --global 'everywhere'
cand -h 'Print help'
Expand Down Expand Up @@ -243,6 +246,7 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand --help 'Print help'
}
&'exhaustive;help'= {
cand empty 'empty'
cand global 'global'
cand action 'action'
cand quote 'quote'
Expand All @@ -253,6 +257,8 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand hint 'hint'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'exhaustive;help;empty'= {
}
&'exhaustive;help;global'= {
cand one 'one'
cand two 'two'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ end

complete -c exhaustive -n "__fish_exhaustive_needs_command" -l generate -d 'generate' -r -f -a "{bash\t'',elvish\t'',fish\t'',powershell\t'',zsh\t''}"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "empty"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "global"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "action"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "quote"
Expand Down Expand Up @@ -119,15 +120,16 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -s H -l host
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l url -r -f
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l email -r -f
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "global"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "action"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "quote"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "value"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "pacman"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "last"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "alias"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "hint"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from global action quote value pacman last alias hint help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "empty"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "global"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "action"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "quote"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "value"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "pacman"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "last"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "alias"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "hint"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and not __fish_seen_subcommand_from empty global action quote value pacman last alias hint help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and __fish_seen_subcommand_from global" -f -a "one"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and __fish_seen_subcommand_from global" -f -a "two"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand help; and __fish_seen_subcommand_from quote" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ _exhaustive() {
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:exhaustive-command-$line[1]:"
case $line[1] in
(global)
(empty)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(global)
_arguments "${_arguments_options[@]}" : \
'--global[everywhere]' \
'-h[Print help]' \
Expand Down Expand Up @@ -413,7 +417,11 @@ _arguments "${_arguments_options[@]}" : \
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:exhaustive-help-command-$line[1]:"
case $line[1] in
(global)
(empty)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(global)
_arguments "${_arguments_options[@]}" : \
":: :_exhaustive__help__global_commands" \
"*::: :->global" \
Expand Down Expand Up @@ -557,6 +565,7 @@ esac
(( $+functions[_exhaustive_commands] )) ||
_exhaustive_commands() {
local commands; commands=(
'empty:' \
'global:' \
'action:' \
'quote:' \
Expand All @@ -579,6 +588,11 @@ _exhaustive__alias_commands() {
local commands; commands=()
_describe -t commands 'exhaustive alias commands' commands "$@"
}
(( $+functions[_exhaustive__empty_commands] )) ||
_exhaustive__empty_commands() {
local commands; commands=()
_describe -t commands 'exhaustive empty commands' commands "$@"
}
(( $+functions[_exhaustive__global_commands] )) ||
_exhaustive__global_commands() {
local commands; commands=(
Expand Down Expand Up @@ -658,6 +672,7 @@ _exhaustive__global__two_commands() {
(( $+functions[_exhaustive__help_commands] )) ||
_exhaustive__help_commands() {
local commands; commands=(
'empty:' \
'global:' \
'action:' \
'quote:' \
Expand All @@ -680,6 +695,11 @@ _exhaustive__help__alias_commands() {
local commands; commands=()
_describe -t commands 'exhaustive help alias commands' commands "$@"
}
(( $+functions[_exhaustive__help__empty_commands] )) ||
_exhaustive__help__empty_commands() {
local commands; commands=()
_describe -t commands 'exhaustive help empty commands' commands "$@"
}
(( $+functions[_exhaustive__help__global_commands] )) ||
_exhaustive__help__global_commands() {
local commands; commands=(
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ fn complete() {
let input = "exhaustive \t\t";
let expected = snapbox::str![[r#"
%
-h --help action value last hint
--generate global quote pacman alias help
-h --help global quote pacman alias help
--generate empty action value last hint
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down Expand Up @@ -260,8 +260,8 @@ fn complete_dynamic_env_toplevel() {
let input = "exhaustive \t\t";
let expected = snapbox::str![[r#"
%
empty action value last hint --generate
global quote pacman alias help --help
action value last hint --generate
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down
5 changes: 3 additions & 2 deletions clap_complete/tests/testsuite/elvish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ fn complete_static_toplevel() {
-h Print help
action action
alias alias
empty empty
global global
help Print this message or the help of the given subcommand(s)
hint hint
Expand Down Expand Up @@ -203,8 +204,8 @@ fn complete_dynamic_env_toplevel() {
let expected = snapbox::str![[r#"
% exhaustive --generate
COMPLETING argument
--generate action global hint pacman value
--help alias help last quote
--generate action empty help last quote
--help alias global hint pacman value
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down
10 changes: 5 additions & 5 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ fn complete() {
let input = "exhaustive \t";
let expected = snapbox::str![[r#"
% exhaustive
action global hint pacman value
alias help (Print this message or the help of the given subcommand(s)) last quote
action empty help (Print this message or the help of the given subcommand(s)) last quote
alias global hint pacman value
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down Expand Up @@ -198,9 +198,9 @@ fn complete_dynamic_env_toplevel() {

let input = "exhaustive \t\t";
let expected = snapbox::str![[r#"
% exhaustive global
global quote pacman alias help (Print this message or the help of the given subcommand(s)) --help (Print help)
action value last hint --generate (generate)
% exhaustive empty
empty action value last hint --generate (generate)
global quote pacman alias help (Print this message or the help of the given subcommand(s)) --help (Print help)
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down
7 changes: 4 additions & 3 deletions clap_complete/tests/testsuite/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ fn complete() {
let input = "exhaustive \t";
let expected = snapbox::str![[r#"
% exhaustive
help -- Print this message or the help of the given subcommand(s)
pacman action global alias value quote hint last --
help -- Print this message or the help of the given subcommand(s)
hint
pacman action global alias value quote empty last --
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down Expand Up @@ -195,7 +196,7 @@ fn complete_dynamic_env_toplevel() {
--generate -- generate
--help -- Print help
help -- Print this message or the help of the given subcommand(s)
action alias global hint last pacman quote value
action alias empty global hint last pacman quote value
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down

0 comments on commit 8e246ef

Please sign in to comment.