Skip to content

Commit

Permalink
fix(complete): make Bash-completion work with subcommand aliases
Browse files Browse the repository at this point in the history
With the previous fixes for clap-rs#4273 and clap-rs#4280 in place, it's now easy to
add support for subcommand aliases, which this commit does. This
addresses clap-rs#4265 for Bash.
  • Loading branch information
martinvonz committed Sep 29, 2022
1 parent 71c4f1f commit 018b5b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clap_complete/src/shells/bash.rs
Expand Up @@ -90,6 +90,13 @@ fn all_subcommands(cmd: &Command) -> String {
cmd.get_name().to_string(),
fn_name.clone(),
));
for alias in cmd.get_visible_aliases() {
subcmds.push((
parent_fn_name.to_string(),
alias.to_string(),
fn_name.clone(),
));
}
for subcmd in cmd.get_subcommands() {
add_command(&fn_name, subcmd, subcmds);
}
Expand Down
3 changes: 3 additions & 0 deletions clap_complete/tests/snapshots/sub_subcommands.bash
Expand Up @@ -18,6 +18,9 @@ _my-app() {
my__app,some_cmd)
cmd="my__app__some_cmd"
;;
my__app,some_cmd_alias)
cmd="my__app__some_cmd"
;;
my__app,test)
cmd="my__app__test"
;;
Expand Down

0 comments on commit 018b5b1

Please sign in to comment.