mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 06:12:40 +00:00
feat(complete): Add completion for help subcommands
Adds parser flags to toggle whether to run the expensive clone logic for completions case. Help completion will only suggest subcommands, not args. clap_complete generator sets the flag.
This commit is contained in:
parent
f2e5b0670a
commit
fdcee9313f
34 changed files with 978 additions and 54 deletions
|
@ -234,6 +234,7 @@ where
|
|||
G: Generator,
|
||||
S: Into<clap::builder::Str>,
|
||||
{
|
||||
cmd.prepare_build_for_completion();
|
||||
cmd.build();
|
||||
|
||||
gen.generate(cmd, buf)
|
||||
|
|
|
@ -39,7 +39,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help)
|
||||
opts="-c [SUBCOMMAND]..."
|
||||
opts="-c test help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -52,6 +52,34 @@ _my-app() {
|
|||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__help__help)
|
||||
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
|
||||
;;
|
||||
my__app__help__test)
|
||||
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
|
||||
;;
|
||||
my__app__test)
|
||||
opts="-d -c -h --help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
|
|
|
@ -33,6 +33,12 @@ set edit:completion:arg-completer[my-app] = {|@words|
|
|||
}
|
||||
&'my-app;help'= {
|
||||
cand -c 'c'
|
||||
cand test 'Subcommand'
|
||||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;help;test'= {
|
||||
}
|
||||
&'my-app;help;help'= {
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
|
|
@ -6,4 +6,6 @@ complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this messag
|
|||
complete -c my-app -n "__fish_seen_subcommand_from test" -s d
|
||||
complete -c my-app -n "__fish_seen_subcommand_from test" -s c
|
||||
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help" -s c
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -s c
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "test" -d 'Subcommand'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
|
|
|
@ -38,6 +38,14 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
|
|||
}
|
||||
'my-app;help' {
|
||||
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c')
|
||||
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand')
|
||||
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
|
||||
break
|
||||
}
|
||||
'my-app;help;test' {
|
||||
break
|
||||
}
|
||||
'my-app;help;help' {
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -39,8 +39,27 @@ _arguments "${_arguments_options[@]}" /
|
|||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*-c[]' /
|
||||
'*::subcommand -- The subcommand whose help message to display:' /
|
||||
":: :_my-app__help_commands" /
|
||||
"*::: :->help" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(help)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
@ -57,9 +76,22 @@ _my-app_commands() {
|
|||
}
|
||||
(( $+functions[_my-app__help_commands] )) ||
|
||||
_my-app__help_commands() {
|
||||
local commands; commands=()
|
||||
local commands; commands=(
|
||||
'test:Subcommand' /
|
||||
'help:Print this message or the help of the given subcommand(s)' /
|
||||
)
|
||||
_describe -t commands 'my-app help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__help_commands] )) ||
|
||||
_my-app__help__help_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__test_commands] )) ||
|
||||
_my-app__help__test_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help test commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__test_commands] )) ||
|
||||
_my-app__test_commands() {
|
||||
local commands; commands=()
|
||||
|
|
|
@ -39,7 +39,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help)
|
||||
opts="[SUBCOMMAND]..."
|
||||
opts="test help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -52,6 +52,34 @@ _my-app() {
|
|||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__help__help)
|
||||
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
|
||||
;;
|
||||
my__app__help__test)
|
||||
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
|
||||
;;
|
||||
my__app__test)
|
||||
opts="-h -V --case --help --version"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
|
|
|
@ -37,6 +37,12 @@ set edit:completion:arg-completer[my-app] = {|@words|
|
|||
cand --version 'Print version information'
|
||||
}
|
||||
&'my-app;help'= {
|
||||
cand test 'tests things'
|
||||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;help;test'= {
|
||||
}
|
||||
&'my-app;help;help'= {
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
|
|
@ -6,3 +6,5 @@ complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this messag
|
|||
complete -c my-app -n "__fish_seen_subcommand_from test" -l case -d 'the case to test' -r
|
||||
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "test" -d 'tests things'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
|
|
|
@ -42,6 +42,14 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'my-app;help' {
|
||||
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
|
||||
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
|
||||
break
|
||||
}
|
||||
'my-app;help;test' {
|
||||
break
|
||||
}
|
||||
'my-app;help;help' {
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -45,8 +45,27 @@ _arguments "${_arguments_options[@]}" /
|
|||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*::subcommand -- The subcommand whose help message to display:' /
|
||||
":: :_my-app__help_commands" /
|
||||
"*::: :->help" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(help)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
@ -63,9 +82,22 @@ _my-app_commands() {
|
|||
}
|
||||
(( $+functions[_my-app__help_commands] )) ||
|
||||
_my-app__help_commands() {
|
||||
local commands; commands=()
|
||||
local commands; commands=(
|
||||
'test:tests things' /
|
||||
'help:Print this message or the help of the given subcommand(s)' /
|
||||
)
|
||||
_describe -t commands 'my-app help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__help_commands] )) ||
|
||||
_my-app__help__help_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__test_commands] )) ||
|
||||
_my-app__help__test_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help test commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__test_commands] )) ||
|
||||
_my-app__test_commands() {
|
||||
local commands; commands=()
|
||||
|
|
|
@ -138,7 +138,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help)
|
||||
opts="[SUBCOMMAND]..."
|
||||
opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -151,6 +151,104 @@ _my-app() {
|
|||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__help__cmd__backslash)
|
||||
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
|
||||
;;
|
||||
my__app__help__cmd__backticks)
|
||||
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
|
||||
;;
|
||||
my__app__help__cmd__brackets)
|
||||
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
|
||||
;;
|
||||
my__app__help__cmd__double__quotes)
|
||||
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
|
||||
;;
|
||||
my__app__help__cmd__expansions)
|
||||
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
|
||||
;;
|
||||
my__app__help__cmd__single__quotes)
|
||||
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
|
||||
;;
|
||||
my__app__help__help)
|
||||
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
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,27 @@ set edit:completion:arg-completer[my-app] = {|@words|
|
|||
cand --help 'Print help information'
|
||||
}
|
||||
&'my-app;help'= {
|
||||
cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''
|
||||
cand cmd-double-quotes 'Can be "always", "auto", or "never"'
|
||||
cand cmd-backticks 'For more information see `echo test`'
|
||||
cand cmd-backslash 'Avoid ''/n'''
|
||||
cand cmd-brackets 'List packages [filter]'
|
||||
cand cmd-expansions 'Execute the shell command with $SHELL'
|
||||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;help;cmd-single-quotes'= {
|
||||
}
|
||||
&'my-app;help;cmd-double-quotes'= {
|
||||
}
|
||||
&'my-app;help;cmd-backticks'= {
|
||||
}
|
||||
&'my-app;help;cmd-backslash'= {
|
||||
}
|
||||
&'my-app;help;cmd-brackets'= {
|
||||
}
|
||||
&'my-app;help;cmd-expansions'= {
|
||||
}
|
||||
&'my-app;help;help'= {
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
|
|
@ -19,3 +19,10 @@ complete -c my-app -n "__fish_seen_subcommand_from cmd-backticks" -s h -l help -
|
|||
complete -c my-app -n "__fish_seen_subcommand_from cmd-backslash" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from cmd-brackets" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from cmd-expansions" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-single-quotes" -d 'Can be /'always/', /'auto/', or /'never/''
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backticks" -d 'For more information see `echo test`'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backslash" -d 'Avoid /'//n/''
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-brackets" -d 'List packages [filter]'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
|
|
|
@ -71,6 +71,34 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'my-app;help' {
|
||||
[CompletionResult]::new('cmd-single-quotes', 'cmd-single-quotes', [CompletionResultType]::ParameterValue, 'Can be ''always'', ''auto'', or ''never''')
|
||||
[CompletionResult]::new('cmd-double-quotes', 'cmd-double-quotes', [CompletionResultType]::ParameterValue, 'Can be "always", "auto", or "never"')
|
||||
[CompletionResult]::new('cmd-backticks', 'cmd-backticks', [CompletionResultType]::ParameterValue, 'For more information see `echo test`')
|
||||
[CompletionResult]::new('cmd-backslash', 'cmd-backslash', [CompletionResultType]::ParameterValue, 'Avoid ''/n''')
|
||||
[CompletionResult]::new('cmd-brackets', 'cmd-brackets', [CompletionResultType]::ParameterValue, 'List packages [filter]')
|
||||
[CompletionResult]::new('cmd-expansions', 'cmd-expansions', [CompletionResultType]::ParameterValue, 'Execute the shell command with $SHELL')
|
||||
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
|
||||
break
|
||||
}
|
||||
'my-app;help;cmd-single-quotes' {
|
||||
break
|
||||
}
|
||||
'my-app;help;cmd-double-quotes' {
|
||||
break
|
||||
}
|
||||
'my-app;help;cmd-backticks' {
|
||||
break
|
||||
}
|
||||
'my-app;help;cmd-backslash' {
|
||||
break
|
||||
}
|
||||
'my-app;help;cmd-brackets' {
|
||||
break
|
||||
}
|
||||
'my-app;help;cmd-expansions' {
|
||||
break
|
||||
}
|
||||
'my-app;help;help' {
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -72,8 +72,47 @@ _arguments "${_arguments_options[@]}" /
|
|||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*::subcommand -- The subcommand whose help message to display:' /
|
||||
":: :_my-app__help_commands" /
|
||||
"*::: :->help" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(help)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(cmd-single-quotes)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(cmd-double-quotes)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(cmd-backticks)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(cmd-backslash)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(cmd-brackets)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(cmd-expansions)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
@ -98,35 +137,78 @@ _my-app__cmd-backslash_commands() {
|
|||
local commands; commands=()
|
||||
_describe -t commands 'my-app cmd-backslash commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__cmd-backslash_commands] )) ||
|
||||
_my-app__help__cmd-backslash_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help cmd-backslash commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__cmd-backticks_commands] )) ||
|
||||
_my-app__cmd-backticks_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app cmd-backticks commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__cmd-backticks_commands] )) ||
|
||||
_my-app__help__cmd-backticks_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help cmd-backticks commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__cmd-brackets_commands] )) ||
|
||||
_my-app__cmd-brackets_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app cmd-brackets commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__cmd-brackets_commands] )) ||
|
||||
_my-app__help__cmd-brackets_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help cmd-brackets commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__cmd-double-quotes_commands] )) ||
|
||||
_my-app__cmd-double-quotes_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app cmd-double-quotes commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__cmd-double-quotes_commands] )) ||
|
||||
_my-app__help__cmd-double-quotes_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help cmd-double-quotes commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__cmd-expansions_commands] )) ||
|
||||
_my-app__cmd-expansions_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app cmd-expansions commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__cmd-expansions_commands] )) ||
|
||||
_my-app__help__cmd-expansions_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help cmd-expansions commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__cmd-single-quotes_commands] )) ||
|
||||
_my-app__cmd-single-quotes_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app cmd-single-quotes commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__cmd-single-quotes_commands] )) ||
|
||||
_my-app__help__cmd-single-quotes_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help cmd-single-quotes commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help_commands] )) ||
|
||||
_my-app__help_commands() {
|
||||
local commands; commands=()
|
||||
local commands; commands=(
|
||||
'cmd-single-quotes:Can be '/''always'/'', '/''auto'/'', or '/''never'/''' /
|
||||
'cmd-double-quotes:Can be "always", "auto", or "never"' /
|
||||
'cmd-backticks:For more information see `echo test`' /
|
||||
'cmd-backslash:Avoid '/''//n'/''' /
|
||||
'cmd-brackets:List packages /[filter/]' /
|
||||
'cmd-expansions:Execute the shell command with $SHELL' /
|
||||
'help:Print this message or the help of the given subcommand(s)' /
|
||||
)
|
||||
_describe -t commands 'my-app help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__help_commands] )) ||
|
||||
_my-app__help__help_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help help commands' commands "$@"
|
||||
}
|
||||
|
||||
_my-app "$@"
|
||||
|
|
|
@ -48,7 +48,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help)
|
||||
opts="[SUBCOMMAND]..."
|
||||
opts="test some_cmd some-cmd-with-hyphens some-hidden-cmd help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -61,6 +61,76 @@ _my-app() {
|
|||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__help__help)
|
||||
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
|
||||
;;
|
||||
my__app__help__some__cmd__with__hyphens)
|
||||
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
|
||||
;;
|
||||
my__app__help__some__hidden__cmd)
|
||||
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
|
||||
;;
|
||||
my__app__help__some_cmd)
|
||||
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
|
||||
;;
|
||||
my__app__help__test)
|
||||
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
|
||||
;;
|
||||
my__app__some__cmd__with__hyphens)
|
||||
opts="-h -V --help --version"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
|
|
|
@ -59,6 +59,21 @@ set edit:completion:arg-completer[my-app] = {|@words|
|
|||
cand --version 'Print version information'
|
||||
}
|
||||
&'my-app;help'= {
|
||||
cand test 'tests things'
|
||||
cand some_cmd 'tests other things'
|
||||
cand some-cmd-with-hyphens 'some-cmd-with-hyphens'
|
||||
cand some-hidden-cmd 'some-hidden-cmd'
|
||||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;help;test'= {
|
||||
}
|
||||
&'my-app;help;some_cmd'= {
|
||||
}
|
||||
&'my-app;help;some-cmd-with-hyphens'= {
|
||||
}
|
||||
&'my-app;help;some-hidden-cmd'= {
|
||||
}
|
||||
&'my-app;help;help'= {
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
|
|
@ -16,3 +16,8 @@ complete -c my-app -n "__fish_seen_subcommand_from some-cmd-with-hyphens" -s h -
|
|||
complete -c my-app -n "__fish_seen_subcommand_from some-cmd-with-hyphens" -s V -l version -d 'Print version information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from some-hidden-cmd" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from some-hidden-cmd" -s V -l version -d 'Print version information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "test" -d 'tests things'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "some_cmd" -d 'tests other things'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "some-cmd-with-hyphens"
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "some-hidden-cmd"
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
|
|
|
@ -67,6 +67,26 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'my-app;help' {
|
||||
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
|
||||
[CompletionResult]::new('some_cmd', 'some_cmd', [CompletionResultType]::ParameterValue, 'tests other things')
|
||||
[CompletionResult]::new('some-cmd-with-hyphens', 'some-cmd-with-hyphens', [CompletionResultType]::ParameterValue, 'some-cmd-with-hyphens')
|
||||
[CompletionResult]::new('some-hidden-cmd', 'some-hidden-cmd', [CompletionResultType]::ParameterValue, 'some-hidden-cmd')
|
||||
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
|
||||
break
|
||||
}
|
||||
'my-app;help;test' {
|
||||
break
|
||||
}
|
||||
'my-app;help;some_cmd' {
|
||||
break
|
||||
}
|
||||
'my-app;help;some-cmd-with-hyphens' {
|
||||
break
|
||||
}
|
||||
'my-app;help;some-hidden-cmd' {
|
||||
break
|
||||
}
|
||||
'my-app;help;help' {
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -71,8 +71,39 @@ _arguments "${_arguments_options[@]}" /
|
|||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*::subcommand -- The subcommand whose help message to display:' /
|
||||
":: :_my-app__help_commands" /
|
||||
"*::: :->help" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(help)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(some_cmd)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(some-cmd-with-hyphens)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(some-hidden-cmd)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
@ -92,24 +123,55 @@ _my-app_commands() {
|
|||
}
|
||||
(( $+functions[_my-app__help_commands] )) ||
|
||||
_my-app__help_commands() {
|
||||
local commands; commands=()
|
||||
local commands; commands=(
|
||||
'test:tests things' /
|
||||
'some_cmd:tests other things' /
|
||||
'some-cmd-with-hyphens:' /
|
||||
'some-hidden-cmd:' /
|
||||
'help:Print this message or the help of the given subcommand(s)' /
|
||||
)
|
||||
_describe -t commands 'my-app help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__help_commands] )) ||
|
||||
_my-app__help__help_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__some-cmd-with-hyphens_commands] )) ||
|
||||
_my-app__help__some-cmd-with-hyphens_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help some-cmd-with-hyphens commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some-cmd-with-hyphens_commands] )) ||
|
||||
_my-app__some-cmd-with-hyphens_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app some-cmd-with-hyphens commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__some-hidden-cmd_commands] )) ||
|
||||
_my-app__help__some-hidden-cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help some-hidden-cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some-hidden-cmd_commands] )) ||
|
||||
_my-app__some-hidden-cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app some-hidden-cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__some_cmd_commands] )) ||
|
||||
_my-app__help__some_cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help some_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some_cmd_commands] )) ||
|
||||
_my-app__some_cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app some_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__test_commands] )) ||
|
||||
_my-app__help__test_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help test commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__test_commands] )) ||
|
||||
_my-app__test_commands() {
|
||||
local commands; commands=()
|
||||
|
|
|
@ -45,7 +45,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help)
|
||||
opts="[SUBCOMMAND]..."
|
||||
opts="test some_cmd help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -58,6 +58,62 @@ _my-app() {
|
|||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__help__help)
|
||||
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
|
||||
;;
|
||||
my__app__help__some_cmd)
|
||||
opts="sub_cmd"
|
||||
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
|
||||
;;
|
||||
my__app__help__some_cmd__sub_cmd)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__help__test)
|
||||
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
|
||||
;;
|
||||
my__app__some_cmd)
|
||||
opts="-h -V --help --version sub_cmd help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
|
@ -73,7 +129,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__some_cmd__help)
|
||||
opts="[SUBCOMMAND]..."
|
||||
opts="sub_cmd help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -86,6 +142,34 @@ _my-app() {
|
|||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__some_cmd__help__help)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__some_cmd__help__sub_cmd)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
my__app__some_cmd__sub_cmd)
|
||||
opts="-h -V --config --help --version"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
|
|
|
@ -53,8 +53,26 @@ set edit:completion:arg-completer[my-app] = {|@words|
|
|||
cand --version 'Print version information'
|
||||
}
|
||||
&'my-app;some_cmd;help'= {
|
||||
cand sub_cmd 'sub-subcommand'
|
||||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;some_cmd;help;sub_cmd'= {
|
||||
}
|
||||
&'my-app;some_cmd;help;help'= {
|
||||
}
|
||||
&'my-app;help'= {
|
||||
cand test 'tests things'
|
||||
cand some_cmd 'top level subcommand'
|
||||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;help;test'= {
|
||||
}
|
||||
&'my-app;help;some_cmd'= {
|
||||
cand sub_cmd 'sub-subcommand'
|
||||
}
|
||||
&'my-app;help;some_cmd;sub_cmd'= {
|
||||
}
|
||||
&'my-app;help;help'= {
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
|
|
@ -14,3 +14,9 @@ complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and not __fish_seen
|
|||
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from sub_cmd" -l config -d 'the other case to test' -r -f -a "{Lest quotes aren/'t escaped. }"
|
||||
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from sub_cmd" -s h -l help -d 'Print help information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from sub_cmd" -s V -l version -d 'Print version information'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from help" -f -a "test" -d 'tests things'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from help" -f -a "some_cmd" -d 'top level subcommand'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from sub_cmd" -f -a "sub_cmd" -d 'sub-subcommand'
|
||||
|
|
|
@ -60,9 +60,33 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'my-app;some_cmd;help' {
|
||||
[CompletionResult]::new('sub_cmd', 'sub_cmd', [CompletionResultType]::ParameterValue, 'sub-subcommand')
|
||||
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
|
||||
break
|
||||
}
|
||||
'my-app;some_cmd;help;sub_cmd' {
|
||||
break
|
||||
}
|
||||
'my-app;some_cmd;help;help' {
|
||||
break
|
||||
}
|
||||
'my-app;help' {
|
||||
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
|
||||
[CompletionResult]::new('some_cmd', 'some_cmd', [CompletionResultType]::ParameterValue, 'top level subcommand')
|
||||
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
|
||||
break
|
||||
}
|
||||
'my-app;help;test' {
|
||||
break
|
||||
}
|
||||
'my-app;help;some_cmd' {
|
||||
[CompletionResult]::new('sub_cmd', 'sub_cmd', [CompletionResultType]::ParameterValue, 'sub-subcommand')
|
||||
break
|
||||
}
|
||||
'my-app;help;some_cmd;sub_cmd' {
|
||||
break
|
||||
}
|
||||
'my-app;help;help' {
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -70,7 +70,62 @@ _arguments "${_arguments_options[@]}" /
|
|||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*::subcommand -- The subcommand whose help message to display:' /
|
||||
":: :_my-app__some_cmd__help_commands" /
|
||||
"*::: :->help" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(help)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-some_cmd-help-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(sub_cmd)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
":: :_my-app__help_commands" /
|
||||
"*::: :->help" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(help)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
(some_cmd)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
":: :_my-app__help__some_cmd_commands" /
|
||||
"*::: :->some_cmd" /
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(some_cmd)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:my-app-help-some_cmd-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(sub_cmd)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
|
@ -79,12 +134,15 @@ esac
|
|||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*::subcommand -- The subcommand whose help message to display:' /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
(( $+functions[_my-app_commands] )) ||
|
||||
|
@ -98,14 +156,38 @@ _my-app_commands() {
|
|||
}
|
||||
(( $+functions[_my-app__help_commands] )) ||
|
||||
_my-app__help_commands() {
|
||||
local commands; commands=()
|
||||
local commands; commands=(
|
||||
'test:tests things' /
|
||||
'some_cmd:top level subcommand' /
|
||||
'help:Print this message or the help of the given subcommand(s)' /
|
||||
)
|
||||
_describe -t commands 'my-app help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__help_commands] )) ||
|
||||
_my-app__help__help_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some_cmd__help_commands] )) ||
|
||||
_my-app__some_cmd__help_commands() {
|
||||
local commands; commands=()
|
||||
local commands; commands=(
|
||||
'sub_cmd:sub-subcommand' /
|
||||
'help:Print this message or the help of the given subcommand(s)' /
|
||||
)
|
||||
_describe -t commands 'my-app some_cmd help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some_cmd__help__help_commands] )) ||
|
||||
_my-app__some_cmd__help__help_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app some_cmd help help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__some_cmd_commands] )) ||
|
||||
_my-app__help__some_cmd_commands() {
|
||||
local commands; commands=(
|
||||
'sub_cmd:sub-subcommand' /
|
||||
)
|
||||
_describe -t commands 'my-app help some_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some_cmd_commands] )) ||
|
||||
_my-app__some_cmd_commands() {
|
||||
local commands; commands=(
|
||||
|
@ -114,11 +196,26 @@ _my-app__some_cmd_commands() {
|
|||
)
|
||||
_describe -t commands 'my-app some_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__some_cmd__sub_cmd_commands] )) ||
|
||||
_my-app__help__some_cmd__sub_cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help some_cmd sub_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some_cmd__help__sub_cmd_commands] )) ||
|
||||
_my-app__some_cmd__help__sub_cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app some_cmd help sub_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__some_cmd__sub_cmd_commands] )) ||
|
||||
_my-app__some_cmd__sub_cmd_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app some_cmd sub_cmd commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__help__test_commands] )) ||
|
||||
_my-app__help__test_commands() {
|
||||
local commands; commands=()
|
||||
_describe -t commands 'my-app help test commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_my-app__test_commands] )) ||
|
||||
_my-app__test_commands() {
|
||||
local commands; commands=()
|
||||
|
|
|
@ -22,16 +22,21 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
subcommands: [
|
||||
{
|
||||
name: "test",
|
||||
description: "Subcommand",
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
name: "-c",
|
||||
},
|
||||
],
|
||||
args: {
|
||||
name: "subcommand",
|
||||
isVariadic: true,
|
||||
isOptional: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
|
|
@ -28,11 +28,16 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
args: {
|
||||
name: "subcommand",
|
||||
isVariadic: true,
|
||||
isOptional: true,
|
||||
},
|
||||
subcommands: [
|
||||
{
|
||||
name: "test",
|
||||
description: "tests things",
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
|
|
@ -65,11 +65,36 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
args: {
|
||||
name: "subcommand",
|
||||
isVariadic: true,
|
||||
isOptional: true,
|
||||
},
|
||||
subcommands: [
|
||||
{
|
||||
name: "cmd-single-quotes",
|
||||
description: "Can be 'always', 'auto', or 'never'",
|
||||
},
|
||||
{
|
||||
name: "cmd-double-quotes",
|
||||
description: "Can be /"always/", /"auto/", or /"never/"",
|
||||
},
|
||||
{
|
||||
name: "cmd-backticks",
|
||||
description: "For more information see `echo test`",
|
||||
},
|
||||
{
|
||||
name: "cmd-backslash",
|
||||
description: "Avoid '//n'",
|
||||
},
|
||||
{
|
||||
name: "cmd-brackets",
|
||||
description: "List packages [filter]",
|
||||
},
|
||||
{
|
||||
name: "cmd-expansions",
|
||||
description: "Execute the shell command with $SHELL",
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
|
|
@ -85,11 +85,27 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
args: {
|
||||
name: "subcommand",
|
||||
isVariadic: true,
|
||||
isOptional: true,
|
||||
},
|
||||
subcommands: [
|
||||
{
|
||||
name: "test",
|
||||
description: "tests things",
|
||||
},
|
||||
{
|
||||
name: "some_cmd",
|
||||
description: "tests other things",
|
||||
},
|
||||
{
|
||||
name: ["some-cmd-with-hyphens", "hyphen"],
|
||||
},
|
||||
{
|
||||
name: "some-hidden-cmd",
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
|
|
@ -58,11 +58,16 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
args: {
|
||||
name: "subcommand",
|
||||
isVariadic: true,
|
||||
isOptional: true,
|
||||
},
|
||||
subcommands: [
|
||||
{
|
||||
name: "sub_cmd",
|
||||
description: "sub-subcommand",
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
@ -79,11 +84,26 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
args: {
|
||||
name: "subcommand",
|
||||
isVariadic: true,
|
||||
isOptional: true,
|
||||
},
|
||||
subcommands: [
|
||||
{
|
||||
name: "test",
|
||||
description: "tests things",
|
||||
},
|
||||
{
|
||||
name: "some_cmd",
|
||||
description: "top level subcommand",
|
||||
subcommands: [
|
||||
{
|
||||
name: "sub_cmd",
|
||||
description: "sub-subcommand",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
|
|
@ -50,9 +50,11 @@ pub(crate) enum AppSettings {
|
|||
DisableHelpSubcommand,
|
||||
DisableVersionFlag,
|
||||
PropagateVersion,
|
||||
DisablePropagatedArgs,
|
||||
Hidden,
|
||||
HidePossibleValues,
|
||||
HelpExpected,
|
||||
ExpandHelpSubcommandTrees,
|
||||
NoBinaryName,
|
||||
#[allow(dead_code)]
|
||||
ColorAuto,
|
||||
|
@ -101,6 +103,8 @@ bitflags! {
|
|||
const INFER_LONG_ARGS = 1 << 43;
|
||||
const IGNORE_ERRORS = 1 << 44;
|
||||
const MULTICALL = 1 << 45;
|
||||
const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46;
|
||||
const DISABLE_PROPAGATED_ARGS = 1 << 47;
|
||||
const NO_OP = 0;
|
||||
}
|
||||
}
|
||||
|
@ -140,10 +144,14 @@ impl_settings! { AppSettings, AppFlags,
|
|||
=> Flags::DISABLE_VERSION_FLAG,
|
||||
PropagateVersion
|
||||
=> Flags::PROPAGATE_VERSION,
|
||||
DisablePropagatedArgs
|
||||
=> Flags::DISABLE_PROPAGATED_ARGS,
|
||||
HidePossibleValues
|
||||
=> Flags::NO_POS_VALUES,
|
||||
HelpExpected
|
||||
=> Flags::HELP_REQUIRED,
|
||||
ExpandHelpSubcommandTrees
|
||||
=> Flags::EXPAND_HELP_SUBCOMMAND_TREES,
|
||||
Hidden
|
||||
=> Flags::HIDDEN,
|
||||
Multicall
|
||||
|
|
|
@ -3740,6 +3740,12 @@ impl Command {
|
|||
Ok(matcher.into_inner())
|
||||
}
|
||||
|
||||
/// Prepare for completions by setting flags useful for that case.
|
||||
/// Call this on the top-level [`Command`] before calling [`Command::build`].
|
||||
pub fn prepare_build_for_completion(&mut self) {
|
||||
self.g_settings.set(AppSettings::ExpandHelpSubcommandTrees);
|
||||
}
|
||||
|
||||
/// Prepare for introspecting on all included [`Command`]s
|
||||
///
|
||||
/// Call this on the top-level [`Command`] when done building and before reading state for
|
||||
|
@ -3782,7 +3788,9 @@ impl Command {
|
|||
|
||||
self._propagate();
|
||||
self._check_help_and_version();
|
||||
self._propagate_global_args();
|
||||
if !self.is_set(AppSettings::DisablePropagatedArgs) {
|
||||
self._propagate_global_args();
|
||||
}
|
||||
|
||||
let mut pos_counter = 1;
|
||||
let hide_pv = self.is_set(AppSettings::HidePossibleValues);
|
||||
|
@ -4062,6 +4070,13 @@ impl Command {
|
|||
debug!("Command::_propagate_global_args:{}", self.name);
|
||||
|
||||
for sc in &mut self.subcommands {
|
||||
if sc.is_set(AppSettings::DisablePropagatedArgs) {
|
||||
debug!(
|
||||
"Command::_propagate skipping {}, has DisablePropagatedArgs",
|
||||
sc.get_name()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
for a in self.args.args().filter(|a| a.is_global_set()) {
|
||||
if sc.find(&a.id).is_some() {
|
||||
debug!(
|
||||
|
@ -4140,15 +4155,40 @@ impl Command {
|
|||
|
||||
if !self.is_set(AppSettings::DisableHelpSubcommand) {
|
||||
debug!("Command::_check_help_and_version: Building help subcommand");
|
||||
let mut help_subcmd = Command::new("help")
|
||||
.about("Print this message or the help of the given subcommand(s)")
|
||||
.arg(
|
||||
let help_about = "Print this message or the help of the given subcommand(s)";
|
||||
|
||||
let mut help_subcmd = if self.is_set(AppSettings::ExpandHelpSubcommandTrees) {
|
||||
// Slow code path to recursively clone all other subcommand subtrees under help
|
||||
let help_subcmd = Command::new("help")
|
||||
.about(help_about)
|
||||
.global_setting(AppSettings::DisableHelpSubcommand)
|
||||
.subcommands(self.get_subcommands().cloned().map(|mut sc| {
|
||||
// Remove args so help completion will not suggest them, only subcommands
|
||||
sc._clear_args_recursive();
|
||||
|
||||
sc.global_setting(AppSettings::DisablePropagatedArgs)
|
||||
.global_setting(AppSettings::DisableHelpFlag)
|
||||
.global_setting(AppSettings::DisableVersionFlag)
|
||||
}));
|
||||
|
||||
let mut help_help_subcmd = Command::new("help").about(help_about);
|
||||
help_help_subcmd.version = None;
|
||||
help_help_subcmd.long_version = None;
|
||||
help_help_subcmd = help_help_subcmd
|
||||
.setting(AppSettings::DisablePropagatedArgs)
|
||||
.setting(AppSettings::DisableHelpFlag)
|
||||
.setting(AppSettings::DisableVersionFlag);
|
||||
|
||||
help_subcmd.subcommand(help_help_subcmd)
|
||||
} else {
|
||||
Command::new("help").about(help_about).arg(
|
||||
Arg::new("subcommand")
|
||||
.action(ArgAction::Append)
|
||||
.num_args(..)
|
||||
.value_name("SUBCOMMAND")
|
||||
.help("The subcommand whose help message to display"),
|
||||
);
|
||||
)
|
||||
};
|
||||
self._propagate_subcommand(&mut help_subcmd);
|
||||
|
||||
// The parser acts like this is set, so let's set it so we don't falsely
|
||||
|
@ -4164,6 +4204,15 @@ impl Command {
|
|||
}
|
||||
}
|
||||
|
||||
fn _clear_args_recursive(&mut self) {
|
||||
self.args.clear();
|
||||
|
||||
if self.has_subcommands() {
|
||||
self.get_subcommands_mut()
|
||||
.for_each(Command::_clear_args_recursive);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn _render_version(&self, use_long: bool) -> String {
|
||||
debug!("Command::_render_version");
|
||||
|
||||
|
|
|
@ -150,6 +150,12 @@ impl MKeyMap {
|
|||
// since it's a cold function, using this wouldn't hurt much
|
||||
.map(|i| self.args.remove(i))
|
||||
}
|
||||
|
||||
/// Remove all args.
|
||||
pub(crate) fn clear(&mut self) {
|
||||
self.args.clear();
|
||||
self.keys.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<&'_ KeyType> for MKeyMap {
|
||||
|
|
Loading…
Reference in a new issue