mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
fix: fixes a bug that was printing the arg name, instead of value name when Arg::last(true) was used
Closes #940
This commit is contained in:
parent
3ed0f70c6e
commit
8713da2372
3 changed files with 25 additions and 13 deletions
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)]
|
||||
|
@ -59,7 +60,11 @@ 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 {
|
||||
""
|
||||
|
@ -67,12 +72,20 @@ impl<'n, 'e> PosBuilder<'n, 'e> {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -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(" ")));
|
||||
|
@ -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)]
|
||||
|
|
Loading…
Add table
Reference in a new issue