Skip to content

Commit

Permalink
fix(Options): values using delimiters no longer parse additional valu…
Browse files Browse the repository at this point in the history
…es after a trailing space

Imagine two args, an option `-o` which accepts mutliple values, and a positional arg `<file>`.
Prior to this change the following (incorrect) parses would have happened:

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

Only when delimters are used, spaces stop parsing values for the option. The follow are now correct

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

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

This still has the bi-product of:

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

This is simply a CLI design and documentation issue (i.e. don't allow options with unlimited
multiple values with positionaln args, or clearly document that positional args go first). This
will also be helped by the upcoming `Arg::require_delimiter`

Relates to #546
  • Loading branch information
kbknapp committed Jun 29, 2016
1 parent 290f61d commit cdc500b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,10 @@ impl<'a, 'b> Parser<'a, 'b>
for v in val.split(delim as u32 as u8) {
ret = try!(self.add_single_val_to_arg(arg, v, matcher));
}
// If there was a delimiter used, we're not looking for more values
if val.contains_byte(delim as u32 as u8) {
ret = None;
}
}
} else {
ret = try!(self.add_single_val_to_arg(arg, val, matcher));
Expand Down

0 comments on commit cdc500b

Please sign in to comment.