Skip to content

Commit

Permalink
fix(complete): Return leading dash on short args
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg authored and epage committed Jul 28, 2023
1 parent 86f8e22 commit 23a8a6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion clap_complete/src/dynamic/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ fn complete_arg(
}

if arg.is_empty() || arg.is_stdio() || arg.is_short() {
let dash_or_arg = if arg.is_empty() {
"-".into()
} else {
arg.to_value_os().to_string_lossy()
};
// HACK: Assuming knowledge of is_stdio
completions.extend(
crate::generator::utils::shorts_and_visible_aliases(cmd)
.into_iter()
// HACK: Need better `OsStr` manipulation
.map(|f| format!("{}{}", arg.to_value_os().to_string_lossy(), f).into()),
.map(|f| format!("{}{}", dash_or_arg, f).into()),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ fn dynamic_complete() {

let input = "exhaustive \t\t";
let expected = r#"%
action complete --global --help hint pacman V --version
alias --generate h help last quote value"#;
action complete --global --help hint pacman -V --version
alias --generate -h help last quote value"#;
let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual);
}

0 comments on commit 23a8a6f

Please sign in to comment.