Skip to content

Commit

Permalink
fix(help): fix formatting of help for flags and options
Browse files Browse the repository at this point in the history
When options or flags have varying lengths of names and "long" version
the formatting gets corrupted because of the use of tabs. This commit
fixes those issues.
  • Loading branch information
kbknapp committed Apr 1, 2015
1 parent c0ef006 commit 6ec1011
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
}else {
None
})
.fold(String::new(), |acc, ref o| acc + &format!("-{}{} ",if let Some(s) = o.short {
format!("{} ", s)
.fold(String::new(), |acc, ref o| acc + &format!("-{}{} ",if let Some(l) = o.long {
format!("-{}=", l)
} else {
format!("-{}=",o.long.unwrap())
format!("{} ",o.short.unwrap())
},o.name));

print!("\t{} {} {} {} {}", self.bin_name.clone().unwrap_or(self.name.clone()),
Expand Down Expand Up @@ -491,7 +491,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
for v in self.flags.values() {
println!("\t{}{}\t{}",
if let Some(s) = v.short{format!("-{}",s)}else{" ".to_owned()},
if let Some(l) = v.long {format!(",--{}",l)}else {" \t".to_owned()},
if let Some(l) = v.long {format!("{}--{}",if v.short.is_some() { ", " } else {" "}, l)}else {" \t".to_owned()},
v.help.unwrap_or(" ") );
}
}
Expand All @@ -501,8 +501,8 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
for v in self.opts.values() {
let mut needs_tab = false;
println!("\t{}{}{}\t{}",
if let Some(s) = v.short{format!("-{} ",s)}else{" ".to_owned()},
if let Some(l) = v.long {format!(",--{}=",l)}else {needs_tab = true; " ".to_owned()},
if let Some(s) = v.short{format!("-{}",s)}else{" ".to_owned()},
if let Some(l) = v.long {format!("{}--{}=",if v.short.is_some() {", "} else {" "},l)}else {needs_tab = true; " ".to_owned()},
format!("{}", v.name),
if let Some(h) = v.help {
format!("{}{}{}",
Expand Down

0 comments on commit 6ec1011

Please sign in to comment.