From 72b453dc170af3050bb123d35364f6da77fc06d7 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Fri, 2 Oct 2015 19:20:56 -0400 Subject: [PATCH] fix(Usage): fixes a bug where required args aren't filtered properly Closes #277 --- src/app/app.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/app.rs b/src/app/app.rs index 6a45a4b8..579347e0 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -3272,13 +3272,28 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ return Err(self.report_error(format!("The argument '{}' isn't valid", Format::Warning(format!("-{}", c))), ClapErrorType::InvalidArgument, - Some(matches.args.keys().map(|k| *k).collect()))); + Some(matches.args.keys() + .map(|k| *k) + .filter(|k| { + if let Some(o) = self.opts.get(k) { + !o.settings.is_set(&ArgSettings::Required) + } else if let Some(p) = self.positionals_name.get(k) { + if let Some(p) = self.positionals_idx.get(p) { + !p.settings.is_set(&ArgSettings::Required) + } else { + true + } + } else { + true + } + }) + .collect()))); } } Err(e) => return Err(e), } } - unreachable!(); + return Ok(None); } fn parse_single_short_flag(&mut self,