mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
fix(RequiredValues): fixes a bug where missing values are parsed as missing arguments
This commit is contained in:
parent
80352bfdb4
commit
93c4a7231b
1 changed files with 9 additions and 8 deletions
17
src/app.rs
17
src/app.rs
|
@ -1356,6 +1356,13 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
|
||||||
Some(ref a) => {
|
Some(ref a) => {
|
||||||
if let Some(o) = self.opts.get(a) {
|
if let Some(o) = self.opts.get(a) {
|
||||||
if o.multiple && self.required.is_empty() { () }
|
if o.multiple && self.required.is_empty() { () }
|
||||||
|
else if !o.multiple {
|
||||||
|
self.report_error(
|
||||||
|
format!("Argument {} requires a value but none was supplied", o),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
Some(matches.args.keys().map(|k| *k).collect::<Vec<_>>() ) );
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
self.report_error(format!("The following required arguments were not \
|
self.report_error(format!("The following required arguments were not \
|
||||||
supplied:\n{}",
|
supplied:\n{}",
|
||||||
|
@ -1371,14 +1378,8 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
|
||||||
} else {
|
} else {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
format!("Argument {} requires a value but none was supplied",
|
format!("Argument {} requires a value but none was supplied",
|
||||||
if let Some(f) = self.flags.get(a) {
|
format!("{}", self.positionals_idx.get(
|
||||||
format!("{}", f)
|
self.positionals_name.get(a).unwrap()).unwrap())),
|
||||||
} else if let Some(o) = self.opts.get(a) {
|
|
||||||
format!("{}", o)
|
|
||||||
} else {
|
|
||||||
format!("{}", self.positionals_idx.get(
|
|
||||||
self.positionals_name.get(a).unwrap()).unwrap())
|
|
||||||
}),
|
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
Some(matches.args.keys().map(|k| *k).collect::<Vec<_>>()));
|
Some(matches.args.keys().map(|k| *k).collect::<Vec<_>>()));
|
||||||
|
|
Loading…
Reference in a new issue