Skip to content

Commit

Permalink
fix: fixes a bug that was printing the arg name, instead of value nam…
Browse files Browse the repository at this point in the history
…e when Arg::last(true) was used

Closes #940
  • Loading branch information
kbknapp committed May 6, 2017
1 parent aeba5bb commit e1fe8ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/app/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
.values()
.find(|p| p.b.is_set(ArgSettings::Last))
.expect(INTERNAL_ERROR_MSG);
debugln!("usage::create_help_usage: {} has .last(true)", pos.name());
debugln!("usage::create_help_usage: '{}' has .last(true)", pos.name());
let req = pos.is_set(ArgSettings::Required);
if req {
usage.push_str(" -- <");
} else {
usage.push_str(" [-- <");
}
usage.push_str(pos.name());
usage.push_str(&*pos.name_no_brackets());
usage.push_str(">");
usage.push_str(pos.multiple_str());
if !req {
Expand Down Expand Up @@ -216,7 +216,7 @@ fn get_args_tag(p: &Parser, incl_reqs: bool) -> Option<String> {
!pos.is_set(ArgSettings::Last)
})
.expect(INTERNAL_ERROR_MSG);
debugln!("usage::get_args_tag:iter: Exactly one, returning {}",
debugln!("usage::get_args_tag:iter: Exactly one, returning '{}'",
pos.name());
return Some(format!(" [{}]{}", pos.name_no_brackets(), pos.multiple_str()));
} else if p.is_set(AS::DontCollapseArgsInUsage) && !p.positionals.is_empty() && incl_reqs {
Expand Down
2 changes: 1 addition & 1 deletion src/args/arg_builder/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'n, 'e> From<Arg<'n, 'e>> for OptBuilder<'n, 'e> {

impl<'n, 'e> Display for OptBuilder<'n, 'e> {
fn fmt(&self, f: &mut Formatter) -> Result {
debugln!("OptBuilder::fmt");
debugln!("OptBuilder::fmt:{}", self.b.name);
let sep = if self.b.is_set(ArgSettings::RequireEquals) {
"="
} else {
Expand Down
30 changes: 21 additions & 9 deletions src/args/arg_builder/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vec_map::{self, VecMap};
// Internal
use Arg;
use args::{ArgSettings, Base, Valued, AnyArg, DispOrder};
use INTERNAL_ERROR_MSG;

#[allow(missing_debug_implementations)]
#[doc(hidden)]
Expand Down Expand Up @@ -59,20 +60,32 @@ impl<'n, 'e> PosBuilder<'n, 'e> {
}

pub fn multiple_str(&self) -> &str {
if self.b.settings.is_set(ArgSettings::Multiple) && self.v.val_names.is_none() {
let mult_vals = self.v
.val_names
.as_ref()
.map_or(true, |ref names| names.len() < 2);
if self.is_set(ArgSettings::Multiple) && mult_vals {
"..."
} else {
""
}
}

pub fn name_no_brackets(&self) -> Cow<str> {
debugln!("PosBuilder::name_no_brackets;");
if let Some(ref names) = self.v.val_names {
Cow::Owned(names.values()
.map(|n| format!("<{}>", n))
.collect::<Vec<_>>()
.join(" "))
debugln!("PosBuilder:name_no_brackets: val_names={:#?}", names);
if names.len() > 1 {
Cow::Owned(names
.values()
.map(|n| format!("<{}>", n))
.collect::<Vec<_>>()
.join(" "))
} else {
Cow::Borrowed(names.values().next().expect(INTERNAL_ERROR_MSG))
}
} else {
debugln!("PosBuilder:name_no_brackets: just name");
Cow::Borrowed(self.b.name)
}
}
Expand All @@ -83,7 +96,8 @@ impl<'n, 'e> Display for PosBuilder<'n, 'e> {
if let Some(ref names) = self.v.val_names {
try!(write!(f,
"{}",
names.values()
names
.values()
.map(|n| format!("<{}>", n))
.collect::<Vec<_>>()
.join(" ")));
Expand Down Expand Up @@ -140,9 +154,7 @@ impl<'n, 'e> DispOrder for PosBuilder<'n, 'e> {
}

impl<'n, 'e> PartialEq for PosBuilder<'n, 'e> {
fn eq(&self, other: &PosBuilder<'n, 'e>) -> bool {
self.b == other.b
}
fn eq(&self, other: &PosBuilder<'n, 'e>) -> bool { self.b == other.b }
}

#[cfg(test)]
Expand Down

0 comments on commit e1fe8ac

Please sign in to comment.