fix(Options): using options with an = no longer parse args after the trailing space as values

Imagine two args, an options `-o` and a positionanl arg `<file>` where the option allows multiple
values. Prior to this change the following (incorrect) parses were occurring:

```
$ prog -o=1 some.txt
o = 1, file
file =
```

This change stops parsing values at the space, only if the `=` was used.

```
$ prog -o=1 some.txt
o = 1
file = some.txt
```

Multiple values are still supported via value delimiters

```
$ prog -o=1,2 some.txt
o = 1, 2
file = some.txt
```

Relates to #546
This commit is contained in:
Kevin K 2016-06-29 13:16:31 -04:00
parent 518a79ddc1
commit 290f61d071

View file

@ -1211,15 +1211,18 @@ impl<'a, 'b> Parser<'a, 'b>
-> ClapResult<Option<&'a str>> {
debugln!("fn=parse_opt;");
validate_multiples!(self, opt, matcher);
let mut has_eq = false;
debug!("Checking for val...");
if let Some(fv) = val {
has_eq = fv.starts_with(&[b'=']);
let v = fv.trim_left_matches(b'=');
if !opt.is_set(ArgSettings::EmptyValues) && v.len_() == 0 {
sdebugln!("Found Empty - Error");
return Err(Error::empty_value(opt, &*self.create_current_usage(matcher), self.color()));
}
sdebugln!("Found - {:?}, len: {}", v, v.len_());
debugln!("{:?} contains '='...{:?}", fv, fv.starts_with(&[b'=']));
try!(self.add_val_to_arg(opt, v, matcher));
} else {
sdebugln!("None");
@ -1229,7 +1232,7 @@ impl<'a, 'b> Parser<'a, 'b>
// Increment or create the group "args"
self.groups_for_arg(opt.name).and_then(|vec| Some(matcher.inc_occurrences_of(&*vec)));
if val.is_none() || (opt.is_set(ArgSettings::Multiple) && matcher.needs_more_vals(opt)) {
if val.is_none() || !has_eq && (opt.is_set(ArgSettings::Multiple) && matcher.needs_more_vals(opt)) {
return Ok(Some(opt.name));
}
Ok(None)