Skip to content

Commit c32cb30

Browse files
committed
fix(complete): Prefer subcommand names over aliases
1 parent 7e0bcca commit c32cb30

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

clap_complete/src/engine/complete.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ fn complete_subcommand(value: &str, cmd: &clap::Command) -> Vec<CompletionCandid
467467
}
468468
}
469469

470-
scs.sort();
471470
scs.dedup();
472471
scs
473472
}

clap_complete/tests/testsuite/engine.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ hello-moon
111111
);
112112
}
113113

114+
#[test]
115+
fn prefer_subcommand_name_over_visible_alias() {
116+
let mut cmd = Command::new("exhaustive")
117+
.subcommand(Command::new("install").visible_alias("i"))
118+
.subcommand(Command::new("remove").visible_alias("rm"));
119+
120+
assert_data_eq!(complete!(cmd, "i[TAB]"), snapbox::str!["install"]);
121+
assert_data_eq!(complete!(cmd, "in[TAB]"), snapbox::str!["install"]);
122+
assert_data_eq!(complete!(cmd, "rm[TAB]"), snapbox::str!["rm"]);
123+
}
124+
114125
#[test]
115126
fn suggest_hidden_possible_value() {
116127
let mut cmd = Command::new("exhaustive").arg(

0 commit comments

Comments
 (0)