Skip to content

Commit

Permalink
fix(MultipleValues): stops evaluating values if the max or exact numb…
Browse files Browse the repository at this point in the history
…er of values was reached
  • Loading branch information
kbknapp committed May 1, 2015
1 parent 82d0363 commit 86d92c9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Vec<_>>()));
}
}
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::<Vec<_>>()));
}
Expand Down

0 comments on commit 86d92c9

Please sign in to comment.