Merge pull request #560 from kbknapp/issue-558

Issue 558
This commit is contained in:
Kevin K 2016-07-01 16:14:22 -04:00 committed by GitHub
commit f10375ebe0
4 changed files with 23 additions and 1 deletions

View file

@ -16,6 +16,10 @@
* completions now continue completing even after first completion ([18fc2e5b](https://github.com/kbknapp/clap-rs/commit/18fc2e5b5af63bf54a94b72cec5e1223d49f4806))
* allows matching on possible values in options ([89cc2026](https://github.com/kbknapp/clap-rs/commit/89cc2026ba9ac69cf44c5254360bbf99236d4f89), closes [#557](https://github.com/kbknapp/clap-rs/issues/557))
#### Bug Fixes
* **AllowLeadingHyphen:** fixes an issue where isn't ignored like it should be with this setting ([96c24c9a](https://github.com/kbknapp/clap-rs/commit/96c24c9a8fa1f85e06138d3cdd133e51659e19d2), closes [#558](https://github.com/kbknapp/clap-rs/issues/558))
<a name="v2.8.0"></a>
## v2.8.0 (2016-06-30)

View file

@ -42,6 +42,7 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
Here's the highlights for v2.9.0
* **Completions:** one can now [generate a bash completions](http://kbknapp.github.io/clap-rs/clap/struct.App.html#method.gen_completions) script at compile time! These completions work with options using [possible values](http://kbknapp.github.io/clap-rs/clap/struct.Arg.html#method.possible_values), [subcommand aliases](http://kbknapp.github.io/clap-rs/clap/struct.App.html#method.aliases), and even multiple levels of subcommands
* Minor bug fixes when using `AppSettings::TrailingVarArg` and `AppSettings::AllowLeadingHyphen`
Here's the highlights for v2.8.0

View file

@ -586,7 +586,9 @@ impl<'a, 'b> Parser<'a, 'b>
}
needs_val_of = try!(self.parse_long_arg(matcher, &arg_os));
continue;
if !(needs_val_of.is_none() && self.is_set(AppSettings::AllowLeadingHyphen)) {
continue;
}
} else if arg_os.starts_with(b"-") && arg_os.len_() != 1 {
needs_val_of = try!(self.parse_short_arg(matcher, &arg_os));
if !(needs_val_of.is_none() && self.is_set(AppSettings::AllowLeadingHyphen)) {
@ -1175,6 +1177,8 @@ impl<'a, 'b> Parser<'a, 'b>
// Handle conflicts, requirements, etc.
arg_post_processing!(self, flag, matcher);
return Ok(None);
} else if self.is_set(AppSettings::AllowLeadingHyphen) {
return Ok(None);
}

View file

@ -234,3 +234,16 @@ fn delim_values_trailingvararg() {
assert!(m.is_present("opt"));
assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["test", "--foo", "-Wl", "-bar"]);
}
#[test]
fn leading_double_hyphen_trailingvararg() {
let m = App::new("positional")
.setting(AppSettings::TrailingVarArg)
.setting(AppSettings::AllowLeadingHyphen)
.arg(
Arg::from_usage("[opt]... 'some pos'"),
)
.get_matches_from(vec!["", "--foo", "-Wl", "bar"]);
assert!(m.is_present("opt"));
assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["--foo", "-Wl", "bar"]);
}