mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
Merge pull request #5549 from shannmu/hidden_aliases
feat(clap_complete): Add support for visible subcommand aliases
This commit is contained in:
commit
4a8d6806d9
2 changed files with 35 additions and 2 deletions
|
@ -334,8 +334,11 @@ fn possible_values(a: &clap::Arg) -> Option<Vec<clap::builder::PossibleValue>> {
|
|||
fn subcommands(p: &clap::Command) -> Vec<(String, Option<StyledStr>)> {
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue