Skip to content

Commit 1e25abf

Browse files
committed
fix(help): change long help --long=long -> --long <long>
1 parent 050d3de commit 1e25abf

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/app.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,10 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
547547
None
548548
})
549549
.fold(String::with_capacity(50), |acc, ref o| acc + &format!("-{}{} ",if let Some(l) = o.long {
550-
format!("-{}=", l)
550+
format!("-{} ", l)
551551
} else {
552-
format!("{} ",o.short.unwrap())
553-
},o.name));
552+
format!("{}=",o.short.unwrap())
553+
},format!("<{}>", o.name)));
554554
req_opts.shrink_to_fit();
555555

556556
// usage.push_str(tab);
@@ -607,21 +607,27 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
607607
let mut longest_flag = 0;
608608
for fl in self.flags
609609
.values()
610-
.filter_map(|ref f| f.long)
611-
.map(|ref l| l.len() + 2) {
610+
.filter(|ref f| f.long.is_some())
611+
// 2='--'
612+
.map(|ref a| a.long.unwrap().len() + 2) {
612613
if fl > longest_flag { longest_flag = fl; }
613614
}
614615
let mut longest_opt= 0;
615616
for ol in self.opts
616617
.values()
617-
.filter_map(|ref f| if f.long.is_some() {let mult = if f.multiple { 3 } else { 0 }; Some(f.long.unwrap().len() + mult + f.name.len() + 3)}else {None}) {
618+
.filter(|ref o| o.long.is_some())
619+
// 3='...'
620+
// 5='-- <>'
621+
.map(|ref a| if a.multiple { 3 } else { 0 } + a.long.unwrap().len() + 5 + a.name.len() ) {
618622
if ol > longest_opt {longest_opt = ol;}
619623
}
620624
if longest_opt == 0 {
621625
for ol in self.opts
622626
.values()
623-
.map(|ref f|
624-
f.name.len() + if f.multiple { 3 } else { 0 } + 2 ){
627+
.filter(|ref o| o.short.is_some())
628+
// 3='...'
629+
// 4='- <>'
630+
.map(|ref a| if a.multiple { 3 } else { 0 } + a.name.len() + 4) {
625631
if ol > longest_opt {longest_opt = ol;}
626632
}
627633
}
@@ -661,11 +667,11 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
661667
format!("{}--{}{}",
662668
if v.short.is_some() { ", " } else {""},
663669
l,
664-
// +2 accounts for the ', ' +4 for tab = 6
670+
// 2='--'
665671
self.get_spaces((longest_flag + 4) - (v.long.unwrap().len() + 2)))
666672
} else {
667673
// 6 is tab (4) + -- (2)
668-
self.get_spaces(longest_flag+6).to_owned()
674+
self.get_spaces(longest_flag + 6).to_owned()
669675
},
670676
v.help.unwrap_or(tab) );
671677
}
@@ -676,22 +682,19 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
676682
for v in self.opts.values() {
677683
// if it supports multiple we add '...' i.e. 3 to the name length
678684
let mult = if v.multiple { 3 } else { 0 };
679-
// let long_len = if v.long.is_some() { v.long.unwrap().len() + 3}else{0};
680-
// let mut needs_tab = false;
681685
println!("{}{}{}{}{}{}",tab,
682686
if let Some(s) = v.short{format!("-{}",s)}else{tab.to_owned()},
683687
if let Some(l) = v.long {
684-
format!("{}--{}=",
688+
format!("{}--{} ",
685689
if v.short.is_some() {", "} else {""},l)
686690
} else {
687691
" ".to_owned()
688692
},
689-
format!("{}{}", v.name, if v.multiple{"..."} else {""}),
693+
format!("<{}>{}", v.name, if v.multiple{"..."} else {""}),
690694
if v.long.is_some() {
691-
self.get_spaces((longest_opt + 4) - (v.long.unwrap().len() + v.name.len() + 2 + mult))
695+
self.get_spaces((longest_opt) - (v.long.unwrap().len() + v.name.len() + mult + 1))
692696
} else {
693-
// 7 is '--=' (3) + tab (4)
694-
self.get_spaces((longest_opt + 6) - (v.name.len() + mult))
697+
self.get_spaces((longest_opt + 3) - (v.name.len() + mult))
695698
},
696699
get_help!(v) );
697700
}

0 commit comments

Comments
 (0)