Skip to content

Commit e5eb6c9

Browse files
committed
fix(help): Integrate 'Possible Values:' into 'Arg::help'
This makes the formatting off as highlighted in #6056
1 parent 594a771 commit e5eb6c9

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

clap_builder/src/output/help_template.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,10 @@ impl HelpTemplate<'_, '_> {
638638
let mut help_is_empty = help.is_empty();
639639
help.replace_newline_var();
640640

641-
if !spec_vals.is_empty() {
641+
let next_line_specs = self.use_long && arg.is_some();
642+
if !spec_vals.is_empty() && !next_line_specs {
642643
if !help_is_empty {
643-
let sep = if self.use_long && arg.is_some() {
644-
"\n\n"
645-
} else {
646-
" "
647-
};
644+
let sep = " ";
648645
help.push_str(sep);
649646
}
650647
help.push_str(spec_vals);
@@ -711,6 +708,19 @@ impl HelpTemplate<'_, '_> {
711708
}
712709
}
713710
}
711+
712+
if !spec_vals.is_empty() && next_line_specs {
713+
let mut help = StyledStr::new();
714+
if !help_is_empty {
715+
let sep = "\n\n";
716+
help.push_str(sep);
717+
}
718+
help.push_str(spec_vals);
719+
720+
help.wrap(avail_chars);
721+
help.indent("", &trailing_indent);
722+
self.writer.push_styled(&help);
723+
}
714724
}
715725

716726
/// Will use next line help on writing args.

tests/ui/help_cmd_stdout.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ Options:
3131
3232
-c, --config <MODE>
3333
Speed configuration
34-
35-
[default: fast]
3634
3735
Possible values:
3836
- fast
3937
- slow: slower than fast
38+
39+
[default: fast]
4040
4141
-f <FRUITS>
4242
List of fruits

tests/ui/help_flag_stdout.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ Options:
3131
3232
-c, --config <MODE>
3333
Speed configuration
34-
35-
[default: fast]
3634
3735
Possible values:
3836
- fast
3937
- slow: slower than fast
38+
39+
[default: fast]
4040
4141
-f <FRUITS>
4242
List of fruits

0 commit comments

Comments
 (0)