mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
fix: Always ensure num_args
is initialized
As we move people off takes_value/multiple_values, this will provide something to check. This was previously blocked on other issues related to flag handling (#4023)
This commit is contained in:
parent
dc5ce00162
commit
479ca76491
2 changed files with 17 additions and 6 deletions
|
@ -3984,6 +3984,14 @@ impl<'help> Arg<'help> {
|
||||||
if val_names_len > 1 {
|
if val_names_len > 1 {
|
||||||
self.settings.set(ArgSettings::MultipleValues);
|
self.settings.set(ArgSettings::MultipleValues);
|
||||||
self.num_vals.get_or_insert(val_names_len.into());
|
self.num_vals.get_or_insert(val_names_len.into());
|
||||||
|
} else {
|
||||||
|
if self.is_multiple_values_set() {
|
||||||
|
self.num_vals.get_or_insert((1..).into());
|
||||||
|
} else if self.is_takes_value_set() {
|
||||||
|
self.num_vals.get_or_insert(1.into());
|
||||||
|
} else {
|
||||||
|
self.num_vals.get_or_insert(0.into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -692,12 +692,15 @@ fn assert_arg(arg: &Arg) {
|
||||||
|
|
||||||
if let Some(num_vals) = arg.get_num_args() {
|
if let Some(num_vals) = arg.get_num_args() {
|
||||||
// This can be the cause of later asserts, so put this first
|
// This can be the cause of later asserts, so put this first
|
||||||
let num_val_names = arg.get_value_names().unwrap_or(&[]).len();
|
if num_vals != 0.into() {
|
||||||
if num_vals.max_values() < num_val_names {
|
// HACK: Don't check for flags to make the derive easier
|
||||||
panic!(
|
let num_val_names = arg.get_value_names().unwrap_or(&[]).len();
|
||||||
"Argument {}: Too many value names ({}) compared to number_of_values ({})",
|
if num_vals.max_values() < num_val_names {
|
||||||
arg.name, num_val_names, num_vals
|
panic!(
|
||||||
);
|
"Argument {}: Too many value names ({}) compared to number_of_values ({})",
|
||||||
|
arg.name, num_val_names, num_vals
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue