Skip to content

Commit aeefb77

Browse files
authored
Merge pull request #5968 from epage/revert
Revert "feat(help): Only print short when required"
2 parents 183cfe3 + ecb2824 commit aeefb77

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

clap_builder/src/output/help_template.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ impl HelpTemplate<'_, '_> {
470470
debug!("HelpTemplate::write_args {_category}");
471471
// The shortest an arg can legally be is 2 (i.e. '-x')
472472
let mut longest = 2;
473-
let mut longest_without_short = 2;
474-
let mut has_short = false;
475473
let mut ord_v = BTreeMap::new();
476474

477475
// Determine the longest
@@ -481,10 +479,6 @@ impl HelpTemplate<'_, '_> {
481479
// args alignment
482480
should_show_arg(self.use_long, arg)
483481
}) {
484-
if !has_short && arg.get_short().is_some() {
485-
has_short = true;
486-
}
487-
488482
if longest_filter(arg) {
489483
let width = display_width(&arg.to_string());
490484
let actual_width = if arg.is_positional() {
@@ -493,9 +487,6 @@ impl HelpTemplate<'_, '_> {
493487
width + SHORT_SIZE
494488
};
495489
longest = longest.max(actual_width);
496-
if !has_short {
497-
longest_without_short = longest_without_short.max(width);
498-
}
499490
debug!(
500491
"HelpTemplate::write_args: arg={:?} longest={}",
501492
arg.get_id(),
@@ -507,10 +498,6 @@ impl HelpTemplate<'_, '_> {
507498
ord_v.insert(key, arg);
508499
}
509500

510-
if !has_short {
511-
longest = longest_without_short;
512-
}
513-
514501
let next_line_help = self.will_args_wrap(args, longest);
515502

516503
for (i, (_, arg)) in ord_v.iter().enumerate() {
@@ -520,22 +507,20 @@ impl HelpTemplate<'_, '_> {
520507
self.writer.push_str("\n");
521508
}
522509
}
523-
self.write_arg(arg, next_line_help, longest, has_short);
510+
self.write_arg(arg, next_line_help, longest);
524511
}
525512
}
526513

527514
/// Writes help for an argument to the wrapped stream.
528-
fn write_arg(&mut self, arg: &Arg, next_line_help: bool, longest: usize, has_short: bool) {
515+
fn write_arg(&mut self, arg: &Arg, next_line_help: bool, longest: usize) {
529516
let spec_vals = &self.spec_vals(arg);
530517

531518
self.writer.push_str(TAB);
532-
if has_short {
533-
self.short(arg);
534-
}
519+
self.short(arg);
535520
self.long(arg);
536521
self.writer
537522
.push_styled(&arg.stylize_arg_suffix(self.styles, None));
538-
self.align_to_about(arg, next_line_help, longest, has_short);
523+
self.align_to_about(arg, next_line_help, longest);
539524

540525
let about = if self.use_long {
541526
arg.get_long_help()
@@ -578,7 +563,7 @@ impl HelpTemplate<'_, '_> {
578563
}
579564

580565
/// Write alignment padding between arg's switches/values and its about message.
581-
fn align_to_about(&mut self, arg: &Arg, next_line_help: bool, longest: usize, has_short: bool) {
566+
fn align_to_about(&mut self, arg: &Arg, next_line_help: bool, longest: usize) {
582567
debug!(
583568
"HelpTemplate::align_to_about: arg={}, next_line_help={}, longest={}",
584569
arg.get_id(),
@@ -590,10 +575,7 @@ impl HelpTemplate<'_, '_> {
590575
debug!("HelpTemplate::align_to_about: printing long help so skip alignment");
591576
0
592577
} else if !arg.is_positional() {
593-
let mut self_len = display_width(&arg.to_string());
594-
if has_short {
595-
self_len += SHORT_SIZE;
596-
}
578+
let self_len = display_width(&arg.to_string()) + SHORT_SIZE;
597579
// Since we're writing spaces from the tab point we first need to know if we
598580
// had a long and short, or just short
599581
let padding = if arg.get_long().is_some() {

examples/find.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Options:
1111
-V, --version Print version
1212

1313
TESTS:
14-
--empty File is empty and is either a regular file or a directory
15-
--name <name> Base of file name (the path with the leading directories removed) matches shell
16-
pattern pattern
14+
--empty File is empty and is either a regular file or a directory
15+
--name <name> Base of file name (the path with the leading directories removed) matches shell
16+
pattern pattern
1717

1818
OPERATORS:
1919
-o, --or expr2 is not evaluate if exp1 is true

tests/builder/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4037,7 +4037,7 @@ Options:
40374037
-h, --help Print help
40384038
40394039
Mixed:
4040-
--long Long only
4040+
--long Long only
40414041
<POSITIONAL> Positional
40424042
40434043
"#]];

0 commit comments

Comments
 (0)