Skip to content

Commit

Permalink
fix(completions): Return leading dash on short args
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Jul 28, 2023
1 parent 3442567 commit e480dda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 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
8 changes: 4 additions & 4 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ fn complete_dynamic() {

let input = "test-dynamic \t";
let expected = r#"% test-dynamic
action cmd-brackets complete last two --help
alias cmd-double-quotes h one V --version
cmd-backslash cmd-expansions help pacman value
cmd-backticks cmd-single-quotes hint quote --global"#;
action cmd-brackets complete one value --help
alias cmd-double-quotes help pacman -h --version
cmd-backslash cmd-expansions hint quote -V
cmd-backticks cmd-single-quotes last two --global"#;
let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual);
}

0 comments on commit e480dda

Please sign in to comment.