diff --git a/src/app/parser.rs b/src/app/parser.rs index 469f422ecb01..2a692e542dc0 100644 --- a/src/app/parser.rs +++ b/src/app/parser.rs @@ -898,8 +898,8 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b { let mut val = None; debug!("Does it contain '='..."); let arg = if full_arg.contains_byte(b'=') { - sdebugln!("Yes"); let (p0, p1) = full_arg.trim_left_matches(b'-').split_at_byte(b'='); + sdebugln!("Yes '{:?}'", p1); val = Some(p1); p0 } else { @@ -995,23 +995,23 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b { opt: &OptBuilder<'a, 'b>, matcher: &mut ArgMatcher<'a>) -> ClapResult> { + debugln!("fn=parse_opt;"); validate_multiples!(self, opt, matcher); + debug!("Checking for val..."); if let Some(v) = val { - if !(opt.is_set(ArgSettings::EmptyValues) && v.len() == 0) { + if !opt.is_set(ArgSettings::EmptyValues) && v.len() == 0 { + sdebugln!("Found Empty - Error"); return Err(Error::empty_value(opt, &*self.create_current_usage(matcher))); } + sdebugln!("Found"); try!(self.add_val_to_arg(opt, v, matcher)); - } + } else { sdebugln!("None"); } - // // If it doesn't allow mutliples, (or a specific number of values), or we don't have any - // // values yet, we want to return the name of this arg so the next arg is parsed as a value - // // otherwise we're done getting values - // if opt.settings.is_set(ArgSettings::Multiple) - // || opt.num_vals.is_some() - // || !matcher.contains(&*opt.name) { - // return Ok(Some(opt.name)); - // } + if (opt.is_set(ArgSettings::Multiple) || opt.num_vals().is_some()) + || val.is_none() { + return Ok(Some(opt.name)); + } Ok(None) } diff --git a/src/osstringext.rs b/src/osstringext.rs index e706940b90ad..75dcaac8080b 100644 --- a/src/osstringext.rs +++ b/src/osstringext.rs @@ -31,7 +31,7 @@ impl OsStrExt2 for OsStr { fn split_at_byte(&self, byte: u8) -> (&OsStr, &OsStr) { let mut i = 0; for b in self.as_bytes() { - if b == &byte { return (OsStr::from_bytes(&self.as_bytes()[..i]), OsStr::from_bytes(&self.as_bytes()[i..])); } + if b == &byte { return (OsStr::from_bytes(&self.as_bytes()[..i]), OsStr::from_bytes(&self.as_bytes()[i+1..])); } i += 1; } (&*self, OsStr::from_bytes(&self.as_bytes()[self.len()..self.len()])) diff --git a/tests/groups.rs b/tests/groups.rs index f854512da75e..4053e07a2efb 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -18,12 +18,14 @@ fn required_group_missing_arg() { #[test] fn group_single_value() { - let m = App::new("group") + let r = App::new("group") .args_from_usage("-f, --flag 'some flag' -c, --color [color] 'some option'") .group(ArgGroup::with_name("grp") .args(&["flag", "color"])) - .get_matches_from(vec!["myprog", "-c", "blue"]); + .get_matches_from_safe(vec!["myprog", "-c", "blue"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("grp")); assert_eq!(m.value_of("grp").unwrap(), "blue"); } @@ -68,12 +70,14 @@ fn group_reqired_flags_empty() { #[test] fn group_multi_value_single_arg() { - let m = App::new("group") + let r = App::new("group") .args_from_usage("-f, --flag 'some flag' -c, --color [color]... 'some option'") .group(ArgGroup::with_name("grp") .args(&["flag", "color"])) - .get_matches_from(vec!["myprog", "-c", "blue", "red", "green"]); + .get_matches_from_safe(vec!["myprog", "-c", "blue", "red", "green"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("grp")); assert_eq!(m.values_of("grp").unwrap().collect::>(), &["blue", "red", "green"]); } diff --git a/tests/opts.rs b/tests/opts.rs index c1c37ec5474e..978726ea6693 100644 --- a/tests/opts.rs +++ b/tests/opts.rs @@ -4,12 +4,14 @@ use clap::{App, Arg}; #[test] fn opts_using_short() { - let m = App::new("opts") + let r = App::new("opts") .args(&mut [ Arg::from_usage("-f [flag] 'some flag'"), Arg::from_usage("-c [color] 'some other flag'") ]) - .get_matches_from(vec!["myprog", "-f", "some", "-c", "other"]); + .get_matches_from_safe(vec!["myprog", "-f", "some", "-c", "other"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("flag")); assert_eq!(m.value_of("flag").unwrap(), "some"); assert!(m.is_present("color")); @@ -18,12 +20,14 @@ fn opts_using_short() { #[test] fn opts_using_long_space() { - let m = App::new("opts") + let r = App::new("opts") .args(&[ Arg::from_usage("--flag [flag] 'some flag'"), Arg::from_usage("--color [color] 'some other flag'") ]) - .get_matches_from(vec!["myprog", "--flag", "some", "--color", "other"]); + .get_matches_from_safe(vec!["myprog", "--flag", "some", "--color", "other"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("flag")); assert_eq!(m.value_of("flag").unwrap(), "some"); assert!(m.is_present("color")); @@ -32,12 +36,14 @@ fn opts_using_long_space() { #[test] fn opts_using_long_equals() { - let m = App::new("opts") + let r = App::new("opts") .args(&[ Arg::from_usage("--flag [flag] 'some flag'"), Arg::from_usage("--color [color] 'some other flag'") ]) - .get_matches_from(vec!["myprog", "--flag=some", "--color=other"]); + .get_matches_from_safe(vec!["myprog", "--flag=some", "--color=other"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("flag")); assert_eq!(m.value_of("flag").unwrap(), "some"); assert!(m.is_present("color")); @@ -46,23 +52,30 @@ fn opts_using_long_equals() { #[test] fn opts_using_mixed() { - let m = App::new("opts") + let r = App::new("opts") .args(&[ Arg::from_usage("-f, --flag [flag] 'some flag'"), Arg::from_usage("-c, --color [color] 'some other flag'") ]) - .get_matches_from(vec!["myprog", "-f", "some", "--color", "other"]); + .get_matches_from_safe(vec!["myprog", "-f", "some", "--color", "other"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("flag")); assert_eq!(m.value_of("flag").unwrap(), "some"); assert!(m.is_present("color")); assert_eq!(m.value_of("color").unwrap(), "other"); +} - let m = App::new("opts") +#[test] +fn opts_using_mixed2() { + let r = App::new("opts") .args(&[ Arg::from_usage("-f, --flag [flag] 'some flag'"), Arg::from_usage("-c, --color [color] 'some other flag'") ]) - .get_matches_from(vec!["myprog", "--flag=some", "-c", "other"]); + .get_matches_from_safe(vec!["myprog", "--flag=some", "-c", "other"]); + assert!(r.is_ok()); + let m = r.unwrap(); assert!(m.is_present("flag")); assert_eq!(m.value_of("flag").unwrap(), "some"); assert!(m.is_present("color"));