diff --git a/clap_complete/src/dynamic/completer.rs b/clap_complete/src/dynamic/completer.rs index 8bf121ea..4c6d9c92 100644 --- a/clap_complete/src/dynamic/completer.rs +++ b/clap_complete/src/dynamic/completer.rs @@ -334,8 +334,11 @@ fn possible_values(a: &clap::Arg) -> Option> { fn subcommands(p: &clap::Command) -> Vec<(String, Option)> { debug!("subcommands: name={}", p.get_name()); debug!("subcommands: Has subcommands...{:?}", p.has_subcommands()); - p.get_subcommands() - .map(|sc| (sc.get_name().to_string(), sc.get_about().cloned())) + .flat_map(|sc| { + sc.get_name_and_visible_aliases() + .into_iter() + .map(|s| (s.to_string(), sc.get_about().cloned())) + }) .collect() } diff --git a/clap_complete/tests/testsuite/dynamic.rs b/clap_complete/tests/testsuite/dynamic.rs index 7d5f98b9..fa482782 100644 --- a/clap_complete/tests/testsuite/dynamic.rs +++ b/clap_complete/tests/testsuite/dynamic.rs @@ -30,6 +30,36 @@ help Print this message or the help of the given subcommand(s) "#]],); } +#[test] +fn suggest_subcommand_aliases() { + let mut cmd = Command::new("exhaustive") + .subcommand( + Command::new("hello-world") + .visible_alias("hello-world-foo") + .alias("hidden-world"), + ) + .subcommand( + Command::new("hello-moon") + .visible_alias("hello-moon-foo") + .alias("hidden-moon"), + ) + .subcommand( + Command::new("goodbye-world") + .visible_alias("goodbye-world-foo") + .alias("hidden-goodbye"), + ); + + assert_data_eq!( + complete!(cmd, "hello"), + snapbox::str![ + "hello-moon +hello-moon-foo +hello-world +hello-world-foo" + ], + ); +} + #[test] fn suggest_long_flag_subset() { let mut cmd = Command::new("exhaustive")