Skip to content

Commit

Permalink
fix(complete): Correctly detect positionals
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 27, 2022
1 parent 53ae382 commit 1922b89
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clap_complete/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
}

let mut current_cmd = &*cmd;
let mut pos_index = 0;
let mut pos_index = 1;
let mut is_escaped = false;
while let Some(arg) = raw_args.next(&mut cursor) {
if cursor == target_cursor {
Expand Down
35 changes: 35 additions & 0 deletions clap_complete/tests/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@ fn suggest_long_flag_subset() {
assert_eq!(completions, ["--help", "--hello-world", "--hello-moon"]);
}

#[test]
fn suggest_possible_value_subset() {
let name = "test";
let mut cmd = clap::Command::new(name).arg(clap::Arg::new("hello-world").possible_values([
"hello-world",
"hello-moon",
"goodbye-world",
]));

let args = [name, "hello"];
let arg_index = 1;
let args = IntoIterator::into_iter(args)
.map(|s| std::ffi::OsString::from(s))
.collect::<Vec<_>>();
let comp_type = clap_complete::dynamic::bash::CompType::default();
let trailing_space = true;
let current_dir = None;

let completions = clap_complete::dynamic::bash::complete(
&mut cmd,
args,
arg_index,
comp_type,
trailing_space,
current_dir,
)
.unwrap();
let completions = completions
.into_iter()
.map(|s| s.to_string_lossy().into_owned())
.collect::<Vec<_>>();

assert_eq!(completions, ["hello-world", "hello-moon"]);
}

#[test]
fn suggest_additional_short_flags() {
let name = "test";
Expand Down

0 comments on commit 1922b89

Please sign in to comment.