From 1dcc80adc19951abf9cf023263e6d5076e69ba5a Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Sun, 15 Dec 2024 22:01:33 -0800 Subject: [PATCH] fix(complete): remove duplicate bash subcmd cases caused by aliases Visible alias completions were causing duplicate case conditions when offering subcommand completions, due to the fact that they share the same function name as the command they are aliasing. This commit deduplicates them so as to not redefine the exact same case statement logic. --- clap_complete/src/aot/shells/bash.rs | 1 + clap_complete/tests/snapshots/sub_subcommands.bash | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/clap_complete/src/aot/shells/bash.rs b/clap_complete/src/aot/shells/bash.rs index d283401949d..6d0be2d297c 100644 --- a/clap_complete/src/aot/shells/bash.rs +++ b/clap_complete/src/aot/shells/bash.rs @@ -132,6 +132,7 @@ fn subcommand_details(cmd: &Command) -> String { .collect::>(); scs.sort(); + scs.dedup(); subcmd_dets.extend(scs.iter().map(|sc| { format!( diff --git a/clap_complete/tests/snapshots/sub_subcommands.bash b/clap_complete/tests/snapshots/sub_subcommands.bash index a6a4663503d..6651d025d91 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.bash +++ b/clap_complete/tests/snapshots/sub_subcommands.bash @@ -152,20 +152,6 @@ _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