From e71d082182e05aadd37b46271e16da1ac0f9d10e Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 28 Sep 2022 21:10:45 -0700 Subject: [PATCH] fix(complete): Fix command alias and Bash With the previous fixes for #4273 and #4280 in place, it's now easy to add support for subcommand aliases, which this commit does. This addresses #4265 for Bash. --- clap_complete/src/shells/bash.rs | 7 +++++++ clap_complete/tests/snapshots/sub_subcommands.bash | 3 +++ 2 files changed, 10 insertions(+) diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs index d7212146363b..8bffbec399ec 100644 --- a/clap_complete/src/shells/bash.rs +++ b/clap_complete/src/shells/bash.rs @@ -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); } diff --git a/clap_complete/tests/snapshots/sub_subcommands.bash b/clap_complete/tests/snapshots/sub_subcommands.bash index a1022c9a4e39..179b67185b33 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.bash +++ b/clap_complete/tests/snapshots/sub_subcommands.bash @@ -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" ;;