From 6ec1011563a746f0578a93b76d45e63878e0f9a8 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 30 Mar 2015 16:59:09 -0400 Subject: [PATCH] fix(help): fix formatting of help for flags and options 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. --- src/app.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app.rs b/src/app.rs index 6376172fe07..02dc6a44a8a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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()), @@ -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(" ") ); } } @@ -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!("{}{}{}",