Skip to content

Commit

Permalink
Merge pull request #5140 from epage/dyn
Browse files Browse the repository at this point in the history
fix(complete): Include positionals in subcommands
  • Loading branch information
epage committed Sep 25, 2023
2 parents c298f6a + 017c258 commit 492ee03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clap_complete/src/dynamic/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn complete(
if let Ok(value) = arg.to_value() {
if let Some(next_cmd) = current_cmd.find_subcommand(value) {
current_cmd = next_cmd;
pos_index = 0;
pos_index = 1;
continue;
}
}
Expand Down
20 changes: 20 additions & 0 deletions clap_complete/tests/testsuite/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ fn suggest_additional_short_flags() {
);
}

#[test]
fn suggest_subcommand_positional() {
let mut cmd = Command::new("exhaustive").subcommand(Command::new("hello-world").arg(
clap::Arg::new("hello-world").value_parser([
PossibleValue::new("hello-world").help("Say hello to the world"),
"hello-moon".into(),
"goodbye-world".into(),
]),
));

snapbox::assert_eq(
"--help\tPrint help (see more with '--help')
-h\tPrint help (see more with '--help')
hello-world\tSay hello to the world
hello-moon
goodbye-world",
complete!(cmd, "hello-world [TAB]"),
);
}

fn complete(cmd: &mut Command, args: impl AsRef<str>, current_dir: Option<&Path>) -> String {
let input = args.as_ref();
let mut args = vec![std::ffi::OsString::from(cmd.get_name())];
Expand Down

0 comments on commit 492ee03

Please sign in to comment.