diff --git a/clap_complete/src/generator/utils.rs b/clap_complete/src/generator/utils.rs index 6ea10d2ab20..a9dd3173b88 100644 --- a/clap_complete/src/generator/utils.rs +++ b/clap_complete/src/generator/utils.rs @@ -47,8 +47,15 @@ pub fn subcommands(p: &Command) -> Vec<(String, String)> { sc.get_name(), sc_bin_name ); - subcmds.push((sc.get_name().to_string(), sc_bin_name.to_string())); + + for alias in sc.get_visible_aliases() { + debug!( + "subcommands:iter: alias={}, bin_name={}", + alias, sc_bin_name + ); + subcmds.push((alias.to_string(), sc_bin_name.to_string())); + } } subcmds diff --git a/clap_complete/tests/snapshots/sub_subcommands.bash b/clap_complete/tests/snapshots/sub_subcommands.bash index ef1925b6f94..a6a4663503d 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.bash +++ b/clap_complete/tests/snapshots/sub_subcommands.bash @@ -55,7 +55,7 @@ _my-app() { case "${cmd}" in my__app) - opts="-C -c -h -V --conf --config --help --version [file] first second test some_cmd help" + opts="-C -c -h -V --conf --config --help --version [file] first second test some_cmd some_cmd_alias help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -152,6 +152,20 @@ _my-app() { 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 + 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) opts="sub_cmd help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then diff --git a/clap_complete/tests/snapshots/sub_subcommands.zsh b/clap_complete/tests/snapshots/sub_subcommands.zsh index 09f4bd7cf17..a931fefd619 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.zsh +++ b/clap_complete/tests/snapshots/sub_subcommands.zsh @@ -97,6 +97,60 @@ esac ;; esac ;; +(some_cmd_alias) +_arguments "${_arguments_options[@]}" \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +":: :_my-app__some_cmd_commands" \ +"*::: :->some_cmd" \ +&& ret=0 + + case $state in + (some_cmd) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:my-app-some_cmd-command-$line[1]:" + case $line[1] in + (sub_cmd) +_arguments "${_arguments_options[@]}" \ +'--config=[the other case to test]: :((Lest\ quotes,\ aren'\''t\ escaped.\:"help,with,comma" +Second\ to\ trigger\ display\ of\ options\:""))' \ +'-h[Print help (see more with '\''--help'\'')]' \ +'--help[Print help (see more with '\''--help'\'')]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +":: :_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" \