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!(), _ => quote!(),
}; };
let value_name = if attrs.has_method("value_name") { let value_name = attrs.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 modifier = match **ty { let modifier = match **ty {
Ty::Bool => quote!(), Ty::Bool => quote!(),
@ -255,7 +247,7 @@ pub fn gen_augment(
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
.takes_value(true) .takes_value(true)
#value_name .value_name(#value_name)
#possible_values #possible_values
#validator #validator
} }
@ -263,7 +255,7 @@ pub fn gen_augment(
Ty::OptionOption => quote_spanned! { ty.span()=> Ty::OptionOption => quote_spanned! { ty.span()=>
.takes_value(true) .takes_value(true)
#value_name .value_name(#value_name)
.min_values(0) .min_values(0)
.max_values(1) .max_values(1)
.multiple_values(false) .multiple_values(false)
@ -272,7 +264,7 @@ pub fn gen_augment(
Ty::OptionVec => quote_spanned! { ty.span()=> Ty::OptionVec => quote_spanned! { ty.span()=>
.takes_value(true) .takes_value(true)
#value_name .value_name(#value_name)
.multiple_values(true) .multiple_values(true)
.min_values(0) .min_values(0)
#validator #validator
@ -289,7 +281,7 @@ pub fn gen_augment(
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
.takes_value(true) .takes_value(true)
#value_name .value_name(#value_name)
.multiple_values(true) .multiple_values(true)
#possible_values #possible_values
#validator #validator
@ -315,7 +307,7 @@ pub fn gen_augment(
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
.takes_value(true) .takes_value(true)
#value_name .value_name(#value_name)
.required(#required) .required(#required)
#possible_values #possible_values
#validator #validator

View file

@ -101,7 +101,7 @@ pub struct Arg<'help> {
pub(crate) disp_ord: usize, pub(crate) disp_ord: usize,
pub(crate) unified_ord: usize, pub(crate) unified_ord: usize,
pub(crate) possible_vals: Vec<&'help str>, 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) num_vals: Option<usize>,
pub(crate) max_occurs: Option<usize>, pub(crate) max_occurs: Option<usize>,
pub(crate) max_vals: Option<usize>, pub(crate) max_vals: Option<usize>,
@ -2494,12 +2494,7 @@ impl<'help> Arg<'help> {
/// [`Arg::takes_value(true)`]: Arg::takes_value() /// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::multiple_values(true)`]: Arg::multiple_values() /// [`Arg::multiple_values(true)`]: Arg::multiple_values()
pub fn value_names(mut self, names: &[&'help str]) -> Self { pub fn value_names(mut self, names: &[&'help str]) -> Self {
let mut i = self.val_names.len(); self.val_names = names.to_vec();
for s in names {
self.val_names.insert(i, s);
i += 1;
}
self.takes_value(true) self.takes_value(true)
} }
@ -2550,10 +2545,9 @@ impl<'help> Arg<'help> {
/// [option]: Arg::takes_value() /// [option]: Arg::takes_value()
/// [positional]: Arg::index() /// [positional]: Arg::index()
/// [`Arg::takes_value(true)`]: Arg::takes_value() /// [`Arg::takes_value(true)`]: Arg::takes_value()
pub fn value_name(mut self, name: &'help str) -> Self { #[inline]
let l = self.val_names.len(); pub fn value_name(self, name: &'help str) -> Self {
self.val_names.insert(l, name); self.value_names(&[name])
self.takes_value(true)
} }
/// Specifies the value of the argument when *not* specified at runtime. /// 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 { if self.val_names.len() > 1 {
Cow::Owned( Cow::Owned(
self.val_names self.val_names
.values() .iter()
.map(|n| format!("<{}>", n)) .map(|n| format!("<{}>", n))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(&*delim), .join(&*delim),
) )
} else { } else {
Cow::Borrowed(self.val_names.values().next().expect(INTERNAL_ERROR_MSG)) Cow::Borrowed(self.val_names.get(0).expect(INTERNAL_ERROR_MSG))
} }
} else { } else {
debug!("Arg::name_no_brackets: just name"); debug!("Arg::name_no_brackets: just name");
@ -4858,7 +4852,7 @@ impl<'help> Display for Arg<'help> {
f, f,
"{}", "{}",
self.val_names self.val_names
.values() .iter()
.map(|n| format!("<{}>", n)) .map(|n| format!("<{}>", n))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(&*delim) .join(&*delim)
@ -4905,7 +4899,7 @@ impl<'help> Display for Arg<'help> {
let num = self.val_names.len(); let num = self.val_names.len();
let mut it = self.val_names.iter().peekable(); let mut it = self.val_names.iter().peekable();
while let Some((_, val)) = it.next() { while let Some(val) = it.next() {
write!(f, "<{}>", val)?; write!(f, "<{}>", val)?;
if it.peek().is_some() { if it.peek().is_some() {
write!(f, "{}", delim)?; write!(f, "{}", delim)?;
@ -5013,7 +5007,6 @@ impl<'help> fmt::Debug for Arg<'help> {
mod test { mod test {
use super::Arg; use super::Arg;
use crate::build::ArgSettings; use crate::build::ArgSettings;
use crate::util::VecMap;
#[test] #[test]
fn flag_display() { fn flag_display() {
@ -5182,9 +5175,7 @@ mod test {
#[test] #[test]
fn positional_display_val_names() { fn positional_display_val_names() {
let mut p2 = Arg::new("pos").index(1); let mut p2 = Arg::new("pos").index(1);
let mut vm = VecMap::new(); let vm = vec!["file1", "file2"];
vm.insert(0, "file1");
vm.insert(1, "file2");
p2.val_names = vm; p2.val_names = vm;
assert_eq!(&*format!("{}", p2), "<file1> <file2>"); assert_eq!(&*format!("{}", p2), "<file1> <file2>");
@ -5193,9 +5184,7 @@ mod test {
#[test] #[test]
fn positional_display_val_names_req() { fn positional_display_val_names_req() {
let mut p2 = Arg::new("pos").index(1).setting(ArgSettings::Required); let mut p2 = Arg::new("pos").index(1).setting(ArgSettings::Required);
let mut vm = VecMap::new(); let vm = vec!["file1", "file2"];
vm.insert(0, "file1");
vm.insert(1, "file2");
p2.val_names = vm; p2.val_names = vm;
assert_eq!(&*format!("{}", p2), "<file1> <file2>"); 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::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -396,7 +396,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -411,7 +411,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -426,7 +426,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -441,7 +441,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -455,7 +455,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -470,7 +470,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -485,7 +485,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -499,7 +499,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -514,7 +514,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -529,7 +529,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -544,7 +544,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -559,7 +559,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -574,7 +574,7 @@ mod test {
assert!(!a.is_set(ArgSettings::MultipleValues)); assert!(!a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -589,7 +589,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -603,7 +603,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -618,7 +618,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -633,7 +633,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleValues)); assert!(a.is_set(ArgSettings::MultipleValues));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -647,7 +647,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -663,7 +663,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -679,7 +679,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -695,7 +695,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -711,7 +711,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -727,7 +727,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -743,7 +743,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -757,7 +757,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -773,7 +773,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -789,7 +789,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -803,7 +803,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -819,7 +819,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -835,7 +835,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -851,7 +851,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -867,7 +867,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -883,7 +883,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -897,7 +897,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -913,7 +913,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -927,7 +927,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -943,7 +943,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -959,7 +959,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -975,7 +975,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -991,7 +991,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -1007,7 +1007,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -1021,7 +1021,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -1037,7 +1037,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -1051,7 +1051,7 @@ mod test {
assert!(a.is_set(ArgSettings::MultipleOccurrences)); assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -1067,7 +1067,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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()); assert!(a.num_vals.is_none());
} }
@ -1083,7 +1083,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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.num_vals.unwrap(), 2);
} }
@ -1099,7 +1099,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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.num_vals.unwrap(), 2);
} }
@ -1115,7 +1115,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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.num_vals.unwrap(), 2);
} }
@ -1131,7 +1131,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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.num_vals.unwrap(), 2);
} }
@ -1294,7 +1294,7 @@ mod test {
); );
assert!(a.is_set(ArgSettings::TakesValue)); assert!(a.is_set(ArgSettings::TakesValue));
assert!(a.is_set(ArgSettings::Required)); 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.num_vals.unwrap(), 2);
assert_eq!(a.default_vals, vec![std::ffi::OsStr::new("a")]); 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::TakesValue));
assert!(!a.is_set(ArgSettings::Required)); 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.num_vals.unwrap(), 2);
assert_eq!(a.default_vals, vec![std::ffi::OsStr::new("a")]); 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'"); let a = Arg::from("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
assert_eq!(a.name, "ñämê"); assert_eq!(a.name, "ñämê");
assert_eq!(a.long, Some("ôpt")); 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")); 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(); let mut it = arg.val_names.iter().peekable();
while let Some((_, val)) = it.next() { while let Some(val) = it.next() {
self.good(&format!("<{}>", val))?; self.good(&format!("<{}>", val))?;
if it.peek().is_some() { if it.peek().is_some() {
self.none(&delim.to_string())?; self.none(&delim.to_string())?;