Skip to content

Commit bff945f

Browse files
committed
fix(args): improve error messages for arguments with mutual exclusions
Closes #51
1 parent 343d47d commit bff945f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/app.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
800800
// let mut req_pos_from_name = None;
801801
if let Some(p) = self.positionals_idx.get(&pos_counter) {
802802
if self.blacklist.contains(p.name) {
803-
self.report_error(format!("The argument \"{}\" is mutually exclusive with one or more other arguments", arg),
803+
self.report_error(format!("The argument \"{}\" cannot be used with one or more of the other specified arguments", arg),
804804
true, true);
805805
}
806806

@@ -872,12 +872,14 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
872872
}
873873
_ => {}
874874
}
875+
876+
self.validate_blacklist(&matches);
877+
875878
if !self.required.is_empty() {
876879
self.report_error("One or more required arguments were not supplied".to_owned(),
877880
true, true);
878881
}
879882

880-
self.validate_blacklist(&matches);
881883

882884
if let Some(sc_name) = subcmd_name {
883885
if let Some(ref mut sc) = self.subcommands.get_mut(&sc_name) {
@@ -952,7 +954,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
952954
if let Some(v) = self.opts.values().filter(|&v| v.long.is_some()).filter(|&v| v.long.unwrap() == arg).nth(0) {
953955
// Ensure this option isn't on the master mutually excludes list
954956
if self.blacklist.contains(v.name) {
955-
self.report_error(format!("The argument --{} is mutually exclusive with one or more other arguments", arg),
957+
self.report_error(format!("The argument --{} cannot be used with one or more of the other specified arguments", arg),
956958
true, true);
957959
}
958960

@@ -1019,7 +1021,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
10191021
if let Some(v) = self.flags.values().filter(|&v| v.long.is_some()).filter(|&v| v.long.unwrap() == arg).nth(0) {
10201022
// Ensure this flag isn't on the mutually excludes list
10211023
if self.blacklist.contains(v.name) {
1022-
self.report_error(format!("The argument --{} is mutually exclusive with one or more other arguments", arg),
1024+
self.report_error(format!("The argument --{} cannot be used with one or more of the other specified arguments", arg),
10231025
true, true);
10241026
}
10251027

@@ -1101,7 +1103,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
11011103
if let Some(v) = self.opts.values().filter(|&v| v.short.is_some()).filter(|&v| v.short.unwrap() == arg_c).nth(0) {
11021104
// Ensure this option isn't on the master mutually excludes list
11031105
if self.blacklist.contains(v.name) {
1104-
self.report_error(format!("The argument --{} is mutually exclusive with one or more other arguments", arg),
1106+
self.report_error(format!("The argument -{} cannot be used with one or more of the other specified arguments", arg),
11051107
true, true);
11061108
}
11071109

@@ -1152,7 +1154,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
11521154
for v in self.flags.values().filter(|&v| v.short.is_some()).filter(|&v| v.short.unwrap() == arg) {
11531155
// Ensure this flag isn't on the mutually excludes list
11541156
if self.blacklist.contains(v.name) {
1155-
self.report_error(format!("The argument -{} is mutually exclusive with one or more other arguments", arg),
1157+
self.report_error(format!("The argument -{} cannot be used with one or more of the other specified arguments", arg),
11561158
true, true);
11571159
}
11581160

@@ -1208,7 +1210,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
12081210
fn validate_blacklist(&self, matches: &ArgMatches<'ar>) {
12091211
for name in self.blacklist.iter() {
12101212
if matches.flags.contains_key(name) {
1211-
self.report_error(format!("The argument {} is mutually exclusive with one or more other arguments",
1213+
self.report_error(format!("The argument {} cannot be used with one or more of the other specified arguments",
12121214
if let Some(s) = self.flags.get(name).unwrap().short {
12131215
format!("-{}", s)
12141216
} else if let Some(l) = self.flags.get(name).unwrap().long {
@@ -1218,17 +1220,17 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
12181220
}), true, true);
12191221
}
12201222
if matches.opts.contains_key(name) {
1221-
self.report_error(format!("The argument {} is mutually exclusive with one or more other arguments",
1222-
if let Some(s) = self.opts.get(name).unwrap().short {
1223-
format!("-{}", s)
1224-
} else if let Some(l) = self.opts.get(name).unwrap().long {
1225-
format!("--{}", l)
1223+
self.report_error(format!("The argument {} cannot be used with one or more of the other specified arguments",
1224+
if let Some(s) = self.opts.get(name).unwrap().long {
1225+
format!("--{}", s)
1226+
} else if let Some(l) = self.opts.get(name).unwrap().short {
1227+
format!("-{}", l)
12261228
} else {
12271229
format!("\"{}\"", name)
12281230
}), true, true);
12291231
}
12301232
if matches.positionals.contains_key(name) {
1231-
self.report_error(format!("The argument \"{}\" is mutually exclusive with one or more other arguments",name),
1233+
self.report_error(format!("The argument \"{}\" cannot be used with one or more of the other specified arguments",name),
12321234
false, true);
12331235
}
12341236
}

0 commit comments

Comments
 (0)