Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clap_complete): Add support for visible subcommand aliases #5549

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clap_complete/src/dynamic/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 30 additions & 0 deletions clap_complete/tests/testsuite/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ help\tPrint this message or the help of the given subcommand(s)"
);
}

#[test]
fn suggest_subcommand_aliases() {
epage marked this conversation as resolved.
Show resolved Hide resolved
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"
],
);
shannmu marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
fn suggest_long_flag_subset() {
let mut cmd = Command::new("exhaustive")
Expand Down
Loading