Skip to content

Commit 86d92c9

Browse files
committed
fix(MultipleValues): stops evaluating values if the max or exact number of values was reached
1 parent 82d0363 commit 86d92c9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/app.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,15 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
11531153
skip = true;
11541154
1
11551155
};
1156-
if !skip {
1157-
continue;
1156+
if let Some(ref mut vals) = o.values {
1157+
let len = vals.len() as u8;
1158+
if let Some(num) = opt.max_vals {
1159+
if len != num { continue }
1160+
} else if let Some(num) = opt.num_vals {
1161+
if len != num { continue }
1162+
} else if !skip {
1163+
continue
1164+
}
11581165
}
11591166
}
11601167
skip = true;
@@ -1742,13 +1749,13 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
17421749
}
17431750
}
17441751
if let Some(num) = f.max_vals {
1745-
if num > vals.len() as u8 {
1752+
if (vals.len() as u8) > num {
17461753
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"}),
17471754
true, true, Some(matches.args.keys().map(|k| *k).collect::<Vec<_>>()));
17481755
}
17491756
}
17501757
if let Some(num) = f.min_vals {
1751-
if num < vals.len() as u8 {
1758+
if (vals.len() as u8) < num {
17521759
self.report_error(format!("The argument {} requires at least {} values, but {} w{} provided", f, num, vals.len(), if vals.len() == 1 {"as"}else{"ere"}),
17531760
true, true, Some(matches.args.keys().map(|k| *k).collect::<Vec<_>>()));
17541761
}

0 commit comments

Comments
 (0)