mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 00:27:13 +00:00
fix: ArgRequiredElseHelp setting now takes precedence over missing required args
Closes #362
This commit is contained in:
parent
27872270db
commit
faad83fbef
1 changed files with 7 additions and 2 deletions
|
@ -2728,12 +2728,17 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
if let Some(a) = self.positionals.values().filter(|p| &p.name == name).next() {
|
if let Some(a) = self.positionals.values().filter(|p| &p.name == name).next() {
|
||||||
if self._validate_blacklist_required(a, matcher) { continue 'outer; }
|
if self._validate_blacklist_required(a, matcher) { continue 'outer; }
|
||||||
}
|
}
|
||||||
return Err(error_builder::MissingRequiredArgument(
|
let err = if self.settings.is_set(&AppSettings::ArgRequiredElseHelp) && matcher.is_empty() {
|
||||||
|
self._help().unwrap_err()
|
||||||
|
} else {
|
||||||
|
error_builder::MissingRequiredArgument(
|
||||||
&*self.get_required_from(&self.required, Some(matcher))
|
&*self.get_required_from(&self.required, Some(matcher))
|
||||||
.iter()
|
.iter()
|
||||||
.fold(String::new(),
|
.fold(String::new(),
|
||||||
|acc, s| acc + &format!("\n\t{}", Format::Error(s))[..]),
|
|acc, s| acc + &format!("\n\t{}", Format::Error(s))[..]),
|
||||||
&*try!(self.create_current_usage(matcher))));
|
&*try!(self.create_current_usage(matcher)))
|
||||||
|
};
|
||||||
|
return Err(err);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue