Skip to content

Commit

Permalink
fix(complete): Correct version check
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 12, 2024
1 parent 6374053 commit cddbb56
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clap_complete/src/dynamic/command/shells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ _clap_complete_NAME() {
compopt -o nospace
fi
}
if [[ \"${{BASH_VERSINFO[0]}}\" -eq 4 && \"${{BASH_VERSINFO[1]}}\" -ge 4 || \"${{BASH_VERSINFO[0]}}\" -gt 4 ]]; then
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
complete -o nospace -o bashdefault -o nosort -F _clap_complete_NAME BIN
else
complete -o nospace -o bashdefault -F _clap_complete_NAME BIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _clap_complete_exhaustive() {
compopt -o nospace
fi
}
if [[ \"${{BASH_VERSINFO[0]}}\" -eq 4 && \"${{BASH_VERSINFO[1]}}\" -ge 4 || \"${{BASH_VERSINFO[0]}}\" -gt 4 ]]; then
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
complete -o nospace -o bashdefault -o nosort -F _clap_complete_exhaustive exhaustive
else
complete -o nospace -o bashdefault -F _clap_complete_exhaustive exhaustive
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/register_minimal.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _clap_complete_my_app() {
compopt -o nospace
fi
}
if [[ /"${{BASH_VERSINFO[0]}}/" -eq 4 && /"${{BASH_VERSINFO[1]}}/" -ge 4 || /"${{BASH_VERSINFO[0]}}/" -gt 4 ]]; then
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
complete -o nospace -o bashdefault -o nosort -F _clap_complete_my_app my-app
else
complete -o nospace -o bashdefault -F _clap_complete_my_app my-app
Expand Down
32 changes: 32 additions & 0 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,35 @@ fn complete() {
fn register_dynamic_completion() {
common::register_example::<completest_pty::BashRuntimeBuilder>("dynamic", "exhaustive");
}

#[test]
#[cfg(all(unix, feature = "unstable-command"))]
fn complete_dynamic() {
if !common::has_command("bash") {
return;
}

let term = completest::Term::new();
let mut runtime =
common::load_runtime::<completest_pty::BashRuntimeBuilder>("dynamic", "exhaustive");

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

let input = "exhaustive quote \t\t";
let expected = snapbox::str![[r#"
%
--single-quotes --brackets --help cmd-backslash cmd-expansions
--double-quotes --expansions --version cmd-backticks cmd-single-quotes
--backticks --choice -h cmd-brackets escape-help
--backslash --global -V cmd-double-quotes help
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

0 comments on commit cddbb56

Please sign in to comment.