Skip to content

Commit

Permalink
fix(complete): Deduplicate bash subcmd cases
Browse files Browse the repository at this point in the history
**Problem:** 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.

**Solution:** Deduplicate them so as to not redefine the exact same case
statement logic.
  • Loading branch information
ribru17 committed Dec 16, 2024
1 parent b1b6f17 commit 48ff72b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
1 change: 1 addition & 0 deletions clap_complete/src/aot/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn subcommand_details(cmd: &Command) -> String {
.collect::<Vec<_>>();

scs.sort();
scs.dedup();

subcmd_dets.extend(scs.iter().map(|sc| {
format!(
Expand Down
14 changes: 0 additions & 14 deletions clap_complete/tests/snapshots/sub_subcommands.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48ff72b

Please sign in to comment.