mirror of
https://github.com/clap-rs/clap
synced 2025-01-18 23:53:54 +00:00
im(Options): adds number of values to options in help/usage
This commit is contained in:
parent
45e481cb1c
commit
c1c993c419
2 changed files with 19 additions and 7 deletions
18
src/app.rs
18
src/app.rs
|
@ -1009,16 +1009,20 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
|
|||
vec.iter().fold(String::new(), |acc, s| {
|
||||
acc + &format!("<{}> ", s)[..]
|
||||
})
|
||||
} else if let Some(num) = v.num_vals {
|
||||
(0..num).fold(String::new(), |acc, _| {
|
||||
acc + &format!("<{}> ", v.name)[..]
|
||||
})
|
||||
} else {
|
||||
format!("<{}>{}", v.name, if v.multiple{"..."} else {""})
|
||||
}),
|
||||
if v.long.is_some() {
|
||||
self.get_spaces(
|
||||
(longest_opt) - (v.long.unwrap().len() + v.name.len() + mult + 1)
|
||||
)
|
||||
} else {
|
||||
self.get_spaces((longest_opt + 3) - (v.name.len() + mult))
|
||||
},
|
||||
if v.long.is_some() {
|
||||
self.get_spaces(
|
||||
(longest_opt) - (v.long.unwrap().len() + v.name.len() + mult + 1)
|
||||
)
|
||||
} else {
|
||||
self.get_spaces((longest_opt + 3) - (v.name.len() + mult))
|
||||
},
|
||||
get_help!(v) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,14 @@ impl<'n> Display for OptBuilder<'n> {
|
|||
format!("-{}", self.short.unwrap())
|
||||
},
|
||||
vec.iter().fold(String::new(),|acc, i| acc + &format!(" <{}>",i)[..]) )
|
||||
} else if let Some(num) = self.num_vals {
|
||||
format!("{}{}",
|
||||
if self.long.is_some() {
|
||||
format!("--{}", self.long.unwrap())
|
||||
} else {
|
||||
format!("-{}", self.short.unwrap())
|
||||
},
|
||||
(0..num).fold(String::new(), |acc, _| acc + &format!(" <{}>", self.name)[..]) )
|
||||
} else {
|
||||
format!("{} <{}>{}",
|
||||
if self.long.is_some() {
|
||||
|
|
Loading…
Reference in a new issue