mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
fix(MultipleValues): stops evaluating values if the max or exact number of values was reached
This commit is contained in:
parent
82d03638d3
commit
86d92c9fdb
1 changed files with 11 additions and 4 deletions
15
src/app.rs
15
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::<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<_>>()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue