From 5ea7eab427a7803bbd5f075ba2af3659e7c77566 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Thu, 1 Mar 2018 06:52:30 -0500 Subject: [PATCH] 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. --- src/app/parser.rs | 3 ++- tests/subcommands.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/app/parser.rs b/src/app/parser.rs index ce483b22..546833bf 100644 --- a/src/app/parser.rs +++ b/src/app/parser.rs @@ -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; diff --git a/tests/subcommands.rs b/tests/subcommands.rs index 388916c7..fa23429d 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -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::>()); + + assert_eq!(expected, actual); + +} \ No newline at end of file