Skip to content

Commit

Permalink
imp(Positional Arguments): now displays value name if appropriate
Browse files Browse the repository at this point in the history
When value names are use, they will be displayed in help and error
messages instead of the argument name. For example, an argument named
`arg` but with the value name `FILE` will be displayed as `[FILE]`.
Likewise multiple value names will be displayed properly such as `[FILE1] [FILE2]`

Closes #420
  • Loading branch information
kbknapp committed Feb 9, 2016
1 parent dfca4ea commit f0a9991
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/args/arg_builder/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,19 @@ impl<'n, 'e> PosBuilder<'n, 'e> {
impl<'n, 'e> Display for PosBuilder<'n, 'e> {
fn fmt(&self, f: &mut Formatter) -> Result {
if self.settings.is_set(ArgSettings::Required) {
try!(write!(f, "<{}>", self.name));
if let Some(ref names) = self.val_names {
try!(write!(f, "{}", names.values().map(|n| format!("<{}>", n)).collect::<Vec<_>>().join(" ")));
} else {
try!(write!(f, "<{}>", self.name));
}
} else {
try!(write!(f, "[{}]", self.name));
if let Some(ref names) = self.val_names {
try!(write!(f, "{}", names.values().map(|n| format!("[{}]", n)).collect::<Vec<_>>().join(" ")));
} else {
try!(write!(f, "[{}]", self.name));
}
}
if self.settings.is_set(ArgSettings::Multiple) {
if self.settings.is_set(ArgSettings::Multiple) && self.val_names.is_none() {
try!(write!(f, "..."));
}

Expand Down

0 comments on commit f0a9991

Please sign in to comment.