Skip to content

Commit

Permalink
Merge #1732
Browse files Browse the repository at this point in the history
1732: Fixed #1622 r=pksunkara a=sphinxc0re



Co-authored-by: Julian Laubstein <contact@julianlaubstein.de>
  • Loading branch information
bors[bot] and sphinxc0re committed Mar 8, 2020
2 parents 19c20f7 + c34a0fd commit 2370665
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parse/validator.rs
Expand Up @@ -170,14 +170,14 @@ impl<'b, 'c, 'z> Validator<'b, 'c, 'z> {
fn build_conflict_err(&self, name: Id, matcher: &ArgMatcher) -> ClapResult<()> {
debugln!("build_err!: name={}", name);
let usg = Usage::new(self.p).create_usage_with_title(&[]);
if self.p.app.find(name).is_some() {
if let Some(other_arg) = self.p.app.find(name) {
for &k in matcher.arg_names() {
if let Some(a) = self.p.app.find(k) {
if let Some(ref v) = a.blacklist {
if v.contains(&name) {
return Err(Error::argument_conflict(
a,
Some(a.to_string()),
Some(other_arg.to_string()),
&*usg,
self.p.app.color(),
));
Expand Down
52 changes: 52 additions & 0 deletions tests/arg_conflicts.rs
@@ -0,0 +1,52 @@
use clap::{App, Arg};

#[test]
fn two_conflicting_arguments() {
let a = App::new("two_conflicting_arguments")
.arg(
Arg::with_name("develop")
.long("develop")
.conflicts_with("production"),
)
.arg(
Arg::with_name("production")
.long("production")
.conflicts_with("develop"),
)
.try_get_matches_from(vec!["", "--develop", "--production"]);

assert!(a.is_err());
let a = a.unwrap_err();
assert_eq!(
a.cause,
"The argument \'--develop\' cannot be used with \'--production\'"
);
}

#[test]
fn three_conflicting_arguments() {
let a = App::new("two_conflicting_arguments")
.arg(
Arg::with_name("one")
.long("one")
.conflicts_with_all(&["two", "three"]),
)
.arg(
Arg::with_name("two")
.long("two")
.conflicts_with_all(&["one", "three"]),
)
.arg(
Arg::with_name("three")
.long("three")
.conflicts_with_all(&["one", "two"]),
)
.try_get_matches_from(vec!["", "--one", "--two", "--three"]);

assert!(a.is_err());
let a = a.unwrap_err();
assert_eq!(
a.cause,
"The argument \'--one\' cannot be used with \'--two\'"
);
}

1 comment on commit 2370665

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 2370665 Previous: 19c20f7 Ratio
build_empty 116 ns/iter (+/- 1) 111 ns/iter (+/- 1) 1.0
parse_empty 1115 ns/iter (+/- 17) 1054 ns/iter (+/- 18) 1.1
parse_simple_with_complex 4371 ns/iter (+/- 60) 4181 ns/iter (+/- 65) 1.0
parse_simple_with_pos 3389 ns/iter (+/- 49) 3160 ns/iter (+/- 65) 1.1
parse_simple_with_opt 3526 ns/iter (+/- 62) 3355 ns/iter (+/- 53) 1.1
parse_simple_with_flag 3141 ns/iter (+/- 47) 3059 ns/iter (+/- 60) 1.0
build_with_pos_ref 264 ns/iter (+/- 4) 277 ns/iter (+/- 6) 0.95
build_with_pos 198 ns/iter (+/- 2) 195 ns/iter (+/- 3) 1.0
build_with_opt_ref 399 ns/iter (+/- 5) 359 ns/iter (+/- 4) 1.1
build_with_opt 304 ns/iter (+/- 4) 294 ns/iter (+/- 6) 1.0
build_with_flag_ref 347 ns/iter (+/- 6) 318 ns/iter (+/- 4) 1.1
build_with_flag 267 ns/iter (+/- 4) 256 ns/iter (+/- 5) 1.0
build_simple 932 ns/iter (+/- 16) 809 ns/iter (+/- 14) 1.2
build_from_usage 5141 ns/iter (+/- 69) 4769 ns/iter (+/- 103) 1.1
build_from_builder 2794 ns/iter (+/- 48) 2646 ns/iter (+/- 44) 1.1
build_from_macros 2840 ns/iter (+/- 39) 2772 ns/iter (+/- 71) 1.0
parse_complex 8470 ns/iter (+/- 149) 8133 ns/iter (+/- 185) 1.0
parse_complex_with_flag 10398 ns/iter (+/- 232) 9421 ns/iter (+/- 223) 1.1
parse_complex_with_opt 10362 ns/iter (+/- 222) 9278 ns/iter (+/- 119) 1.1
parse_complex_with_pos 10232 ns/iter (+/- 152) 9554 ns/iter (+/- 161) 1.1
parse_complex_with_sc 12100 ns/iter (+/- 185) 11121 ns/iter (+/- 251) 1.1
parse_complex_with_sc_flag 12939 ns/iter (+/- 233) 12071 ns/iter (+/- 206) 1.1
parse_complex_with_sc_opt 13255 ns/iter (+/- 227) 12395 ns/iter (+/- 265) 1.1
parse_complex_with_sc_pos 12401 ns/iter (+/- 353) 11767 ns/iter (+/- 214) 1.1
parse_complex1 16472 ns/iter (+/- 539) 15562 ns/iter (+/- 479) 1.1
parse_complex2 19249 ns/iter (+/- 565) 17882 ns/iter (+/- 472) 1.1
parse_args_negate_scs 17247 ns/iter (+/- 172) 17277 ns/iter (+/- 352) 1.0
parse_complex_with_sc_complex 14540 ns/iter (+/- 452) 13725 ns/iter (+/- 288) 1.1
example1 18226 ns/iter (+/- 511) 17058 ns/iter (+/- 295) 1.1
example2 382128 ns/iter (+/- 40,058) 425550 ns/iter (+/- 49,057) 0.90
example3 20345 ns/iter (+/- 497) 18816 ns/iter (+/- 374) 1.1
example4 14136 ns/iter (+/- 305) 13105 ns/iter (+/- 233) 1.1
example5 487339 ns/iter (+/- 38,210) 517820 ns/iter (+/- 39,343) 0.94
example6 11084 ns/iter (+/- 206) 9994 ns/iter (+/- 159) 1.1
example7 15678 ns/iter (+/- 364) 14435 ns/iter (+/- 311) 1.1
example8 15407 ns/iter (+/- 393) 14502 ns/iter (+/- 287) 1.1
example10 429916 ns/iter (+/- 38,885) 459988 ns/iter (+/- 43,442) 0.93
example4_template 13017 ns/iter (+/- 279) 12363 ns/iter (+/- 331) 1.1
build_rg_with_short_help 13026 ns/iter (+/- 317) 11990 ns/iter (+/- 215) 1.1
build_rg_with_long_help 13480 ns/iter (+/- 277) 12901 ns/iter (+/- 231) 1.0
write_rg_short_help 121387 ns/iter (+/- 2,170) 114229 ns/iter (+/- 1,920) 1.1
write_rg_long_help 270861 ns/iter (+/- 7,886) 261900 ns/iter (+/- 8,646) 1.0
parse_rg 29213 ns/iter (+/- 416) 26814 ns/iter (+/- 520) 1.1
parse_rg_with_complex 43995 ns/iter (+/- 873) 37916 ns/iter (+/- 746) 1.2
parse_rg_with_lots 995703 ns/iter (+/- 12,349) 872343 ns/iter (+/- 13,292) 1.1
build_rustup 15569 ns/iter (+/- 243) 14465 ns/iter (+/- 307) 1.1
parse_rustup 19650 ns/iter (+/- 316) 18205 ns/iter (+/- 357) 1.1
parse_rustup_with_sc 19935 ns/iter (+/- 415) 18361 ns/iter (+/- 394) 1.1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.