Skip to content

Commit

Permalink
fix(builder): Allow value terminated multiple positional values
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 19, 2023
1 parent 130b2ff commit 1ee2e95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions clap_builder/src/builder/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ fn _verify_positionals(cmd: &Command) -> bool {
.get_positionals()
.filter(|p| {
p.is_multiple_values_set()
&& p.get_value_terminator().is_none()
&& !p.get_num_args().expect(INTERNAL_ERROR_MSG).is_fixed()
})
.count();
Expand Down
21 changes: 19 additions & 2 deletions tests/builder/multiple_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,8 @@ fn multiple_vals_with_hyphen() {
}

#[test]
#[should_panic]
fn multiple_positional_multiple_values() {
let _ = Command::new("do")
let res = Command::new("do")
.arg(
Arg::new("cmd1")
.action(ArgAction::Set)
Expand All @@ -1440,6 +1439,24 @@ fn multiple_positional_multiple_values() {
"/home/clap",
"foo",
]);
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind());

let m = res.unwrap();
let cmd1: Vec<_> = m
.get_many::<String>("cmd1")
.unwrap()
.map(|v| v.as_str())
.collect();
assert_eq!(
&cmd1,
&["find", "-type", "f", "-name", "special", "/home/clap"]
);
let cmd2: Vec<_> = m
.get_many::<String>("cmd2")
.unwrap()
.map(|v| v.as_str())
.collect();
assert_eq!(&cmd2, &["foo"]);
}

#[test]
Expand Down

0 comments on commit 1ee2e95

Please sign in to comment.