mirror of
https://github.com/clap-rs/clap
synced 2024-09-21 06:41:54 +00:00
Port 1161 fix to v3
Copy the fix from https://github.com/kbknapp/clap-rs/pull/1162 into the v3 parser, and add a test to protect against regressions in the expected behavior of example 22.
This commit is contained in:
parent
bd08e73e54
commit
5ea7eab427
2 changed files with 23 additions and 1 deletions
|
@ -369,7 +369,8 @@ where
|
|||
self.unset(AS::ValidNegNumFound);
|
||||
// Is this a new argument, or values from a previous option?
|
||||
let starts_new_arg = self.is_new_arg(&arg_os, needs_val_of);
|
||||
if arg_os.starts_with(b"--") && arg_os.len_() == 2 && starts_new_arg {
|
||||
if !self.is_set(AS::TrailingValues) &&
|
||||
arg_os.starts_with(b"--") && arg_os.len_() == 2 && starts_new_arg {
|
||||
debugln!("Parser::get_matches_with: setting TrailingVals=true");
|
||||
self.set(AS::TrailingValues);
|
||||
continue;
|
||||
|
|
|
@ -212,3 +212,24 @@ fn issue_1031_args_with_same_name_no_more_vals() {
|
|||
assert_eq!(m.value_of("ui-path"), Some("value"));
|
||||
assert_eq!(m.subcommand_name(), Some("signer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1161_multiple_hyphen_hyphen() {
|
||||
// from example 22
|
||||
let res = App::new("myprog")
|
||||
.arg(Arg::with_name("eff").short("f"))
|
||||
.arg(Arg::with_name("pea").short("p").takes_value(true))
|
||||
.arg(Arg::with_name("slop").multiple(true).last(true))
|
||||
.get_matches_from_safe(vec!["-f", "-p=bob", "--", "sloppy", "slop", "-a", "--", "subprogram", "position", "args"]);
|
||||
|
||||
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
|
||||
let expected = Some(vec!["sloppy", "slop", "-a", "--", "subprogram", "position", "args"]);
|
||||
let actual = m
|
||||
.values_of("slop")
|
||||
.map(|vals| vals.collect::<Vec<_>>());
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
}
|
Loading…
Reference in a new issue