mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
fix(complete): When completing -[TAB], prioritize shorts
This commit is contained in:
parent
7422785a85
commit
8af051c439
2 changed files with 20 additions and 6 deletions
|
@ -157,8 +157,7 @@ fn complete_arg(
|
|||
completions.extend(complete_arg_value(arg.to_value(), positional, current_dir));
|
||||
}
|
||||
|
||||
if arg.is_empty() || arg.is_stdio() {
|
||||
// HACK: Assuming knowledge of is_stdio
|
||||
if arg.is_empty() {
|
||||
completions.extend(longs_and_visible_aliases(cmd));
|
||||
completions.extend(hidden_longs_aliases(cmd));
|
||||
|
||||
|
@ -172,6 +171,21 @@ fn complete_arg(
|
|||
.into_iter()
|
||||
.map(|comp| comp.add_prefix(dash_or_arg.to_string())),
|
||||
);
|
||||
} else if arg.is_stdio() {
|
||||
// HACK: Assuming knowledge of is_stdio
|
||||
let dash_or_arg = if arg.is_empty() {
|
||||
"-".into()
|
||||
} else {
|
||||
arg.to_value_os().to_string_lossy()
|
||||
};
|
||||
completions.extend(
|
||||
shorts_and_visible_aliases(cmd)
|
||||
.into_iter()
|
||||
.map(|comp| comp.add_prefix(dash_or_arg.to_string())),
|
||||
);
|
||||
|
||||
completions.extend(longs_and_visible_aliases(cmd));
|
||||
completions.extend(hidden_longs_aliases(cmd));
|
||||
} else if arg.is_escape() {
|
||||
// HACK: Assuming knowledge of is_escape
|
||||
completions.extend(longs_and_visible_aliases(cmd));
|
||||
|
|
|
@ -1114,11 +1114,11 @@ pos-c
|
|||
assert_data_eq!(
|
||||
complete!(cmd, "-[TAB]"),
|
||||
snapbox::str![[r#"
|
||||
--required-flag
|
||||
--optional-flag
|
||||
--long-flag
|
||||
--help Print help
|
||||
-r
|
||||
-o
|
||||
-s
|
||||
-h Print help
|
||||
--long-flag
|
||||
"#]]
|
||||
);
|
||||
assert_data_eq!(
|
||||
|
|
Loading…
Reference in a new issue