fix!: value_name/value_names should not append

Instead they should behave like `default_value`/`default_values`.

In implementingt this, I didn't see any reason to be using a `VecMap`.
In fact, this helped simplify the code / make intent clearer.

With this, we are also able to simplify the derive macro work from #2633.

Fixes #2634

BREAKING CHANGE: `value_name`/`value_names` always overwrite, rather
than append.  We expect the impact to be minimal.
This commit is contained in:
Ed Page 2021-08-13 15:19:30 -05:00
parent 24bfd2b92c
commit 2eb22e2b36
4 changed files with 71 additions and 90 deletions

View file

@ -231,15 +231,7 @@ pub fn gen_augment(
_ => quote!(),
};
let value_name = if attrs.has_method("value_name") {
// `value_name` appends, so don't touch it if the user does.
quote!()
} else {
let value_name = attrs.value_name();
quote_spanned! { func.span()=>
.value_name(#value_name)
}
};
let value_name = attrs.value_name();
let modifier = match **ty {
Ty::Bool => quote!(),
@ -255,7 +247,7 @@ pub fn gen_augment(
quote_spanned! { ty.span()=>
.takes_value(true)
#value_name
.value_name(#value_name)
#possible_values
#validator
}
@ -263,7 +255,7 @@ pub fn gen_augment(
Ty::OptionOption => quote_spanned! { ty.span()=>
.takes_value(true)
#value_name
.value_name(#value_name)
.min_values(0)
.max_values(1)
.multiple_values(false)
@ -272,7 +264,7 @@ pub fn gen_augment(
Ty::OptionVec => quote_spanned! { ty.span()=>
.takes_value(true)
#value_name
.value_name(#value_name)
.multiple_values(true)
.min_values(0)
#validator
@ -289,7 +281,7 @@ pub fn gen_augment(
quote_spanned! { ty.span()=>
.takes_value(true)
#value_name
.value_name(#value_name)
.multiple_values(true)
#possible_values
#validator
@ -315,7 +307,7 @@ pub fn gen_augment(
quote_spanned! { ty.span()=>
.takes_value(true)
#value_name
.value_name(#value_name)
.required(#required)
#possible_values
#validator

View file

@ -101,7 +101,7 @@ pub struct Arg<'help> {
pub(crate) disp_ord: usize,
pub(crate) unified_ord: usize,
pub(crate) possible_vals: Vec<&'help str>,
pub(crate) val_names: VecMap<&'help str>,
pub(crate) val_names: Vec<&'help str>,
pub(crate) num_vals: Option<usize>,
pub(crate) max_occurs: Option<usize>,
pub(crate) max_vals: Option<usize>,
@ -2494,12 +2494,7 @@ impl<'help> Arg<'help> {
/// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::multiple_values(true)`]: Arg::multiple_values()
pub fn value_names(mut self, names: &[&'help str]) -> Self {
let mut i = self.val_names.len();
for s in names {
self.val_names.insert(i, s);
i += 1;
}
self.val_names = names.to_vec();
self.takes_value(true)
}
@ -2550,10 +2545,9 @@ impl<'help> Arg<'help> {
/// [option]: Arg::takes_value()
/// [positional]: Arg::index()
/// [`Arg::takes_value(true)`]: Arg::takes_value()
pub fn value_name(mut self, name: &'help str) -> Self {
let l = self.val_names.len();
self.val_names.insert(l, name);
self.takes_value(true)
#[inline]
pub fn value_name(self, name: &'help str) -> Self {
self.value_names(&[name])
}
/// Specifies the value of the argument when *not* specified at runtime.
@ -4675,13 +4669,13 @@ impl<'help> Arg<'help> {
if self.val_names.len() > 1 {
Cow::Owned(
self.val_names
.values()
.iter()
.map(|n| format!("<{}>", n))
.collect::<Vec<_>>()
.join(&*delim),
)
} else {
Cow::Borrowed(self.val_names.values().next().expect(INTERNAL_ERROR_MSG))
Cow::Borrowed(self.val_names.get(0).expect(INTERNAL_ERROR_MSG))
}
} else {
debug!("Arg::name_no_brackets: just name");
@ -4858,7 +4852,7 @@ impl<'help> Display for Arg<'help> {
f,
"{}",
self.val_names
.values()
.iter()
.map(|n| format!("<{}>", n))
.collect::<Vec<_>>()
.join(&*delim)
@ -4905,7 +4899,7 @@ impl<'help> Display for Arg<'help> {
let num = self.val_names.len();
let mut it = self.val_names.iter().peekable();
while let Some((_, val)) = it.next() {
while let Some(val) = it.next() {
write!(f, "<{}>", val)?;
if it.peek().is_some() {
write!(f, "{}", delim)?;
@ -5013,7 +5007,6 @@ impl<'help> fmt::Debug for Arg<'help> {
mod test {
use super::Arg;
use crate::build::ArgSettings;
use crate::util::VecMap;
#[test]
fn flag_display() {
@ -5182,9 +5175,7 @@ mod test {
#[test]
fn positional_display_val_names() {
let mut p2 = Arg::new("pos").index(1);
let mut vm = VecMap::new();
vm.insert(0, "file1");
vm.insert(1, "file2");
let vm = vec!["file1", "file2"];
p2.val_names = vm;
assert_eq!(&*format!("{}", p2), "<file1> <file2>");
@ -5193,9 +5184,7 @@ mod test {
#[test]
fn positional_display_val_names_req() {
let mut p2 = Arg::new("pos").index(1).setting(ArgSettings::Required);
let mut vm = VecMap::new();
vm.insert(0, "file1");
vm.insert(1, "file2");
let vm = vec!["file1", "file2"];
p2.val_names = vm;
assert_eq!(&*format!("{}", p2), "<file1> <file2>");

View file

@ -381,7 +381,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -396,7 +396,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -411,7 +411,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -426,7 +426,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -441,7 +441,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -455,7 +455,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -470,7 +470,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -485,7 +485,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -499,7 +499,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -514,7 +514,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -529,7 +529,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -544,7 +544,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -559,7 +559,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -574,7 +574,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -589,7 +589,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -603,7 +603,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -618,7 +618,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -633,7 +633,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -647,7 +647,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -663,7 +663,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -679,7 +679,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -695,7 +695,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -711,7 +711,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -727,7 +727,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -743,7 +743,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -757,7 +757,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -773,7 +773,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -789,7 +789,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -803,7 +803,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -819,7 +819,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -835,7 +835,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -851,7 +851,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -867,7 +867,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -883,7 +883,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -897,7 +897,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -913,7 +913,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -927,7 +927,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -943,7 +943,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -959,7 +959,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -975,7 +975,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -991,7 +991,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -1007,7 +1007,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -1021,7 +1021,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -1037,7 +1037,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -1051,7 +1051,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"opt"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"opt"]);
assert!(a.num_vals.is_none());
}
@ -1067,7 +1067,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"option"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"option"]);
assert!(a.num_vals.is_none());
}
@ -1083,7 +1083,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.num_vals.unwrap(), 2);
}
@ -1099,7 +1099,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.num_vals.unwrap(), 2);
}
@ -1115,7 +1115,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.num_vals.unwrap(), 2);
}
@ -1131,7 +1131,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.num_vals.unwrap(), 2);
}
@ -1294,7 +1294,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.num_vals.unwrap(), 2);
assert_eq!(a.default_vals, vec![std::ffi::OsStr::new("a")]);
}
@ -1311,7 +1311,7 @@ mod test {
);
assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"file", &"mode"]);
assert_eq!(a.num_vals.unwrap(), 2);
assert_eq!(a.default_vals, vec![std::ffi::OsStr::new("a")]);
}
@ -1338,7 +1338,7 @@ mod test {
let a = Arg::from("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
assert_eq!(a.name, "ñämê");
assert_eq!(a.long, Some("ôpt"));
assert_eq!(a.val_names.values().collect::<Vec<_>>(), [&"üñíčöĐ€"]);
assert_eq!(a.val_names.iter().collect::<Vec<_>>(), [&"üñíčöĐ€"]);
assert_eq!(a.about, Some("hælp"));
}
}

View file

@ -348,7 +348,7 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
}
_ => {
let mut it = arg.val_names.iter().peekable();
while let Some((_, val)) = it.next() {
while let Some(val) = it.next() {
self.good(&format!("<{}>", val))?;
if it.peek().is_some() {
self.none(&delim.to_string())?;