From 86d92c9fdbf9f422442e9562977bbaf268dbbae1 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Thu, 30 Apr 2015 22:10:12 -0400 Subject: [PATCH] fix(MultipleValues): stops evaluating values if the max or exact number of values was reached --- src/app.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index ce498b50767..78bfcf45a01 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1153,8 +1153,15 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ skip = true; 1 }; - if !skip { - continue; + if let Some(ref mut vals) = o.values { + let len = vals.len() as u8; + if let Some(num) = opt.max_vals { + if len != num { continue } + } else if let Some(num) = opt.num_vals { + if len != num { continue } + } else if !skip { + continue + } } } skip = true; @@ -1742,13 +1749,13 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ } } if let Some(num) = f.max_vals { - if num > vals.len() as u8 { + if (vals.len() as u8) > num { self.report_error(format!("The argument {} requires no more than {} values, but {} w{} provided", f, num, vals.len(), if vals.len() == 1 {"as"}else{"ere"}), true, true, Some(matches.args.keys().map(|k| *k).collect::>())); } } if let Some(num) = f.min_vals { - if num < vals.len() as u8 { + if (vals.len() as u8) < num { self.report_error(format!("The argument {} requires at least {} values, but {} w{} provided", f, num, vals.len(), if vals.len() == 1 {"as"}else{"ere"}), true, true, Some(matches.args.keys().map(|k| *k).collect::>())); }