Skip to content

Commit 220875b

Browse files
authored
Merge pull request #6091 from epage/possible
fix(help): Integrate 'Possible Values:' into 'Arg::help'
2 parents 4c6fd93 + e5eb6c9 commit 220875b

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

clap_builder/src/output/help_template.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,18 +635,19 @@ impl HelpTemplate<'_, '_> {
635635
let trailing_indent = self.get_spaces(trailing_indent);
636636

637637
let mut help = about.clone();
638+
let mut help_is_empty = help.is_empty();
638639
help.replace_newline_var();
639-
if !spec_vals.is_empty() {
640-
if !help.is_empty() {
641-
let sep = if self.use_long && arg.is_some() {
642-
"\n\n"
643-
} else {
644-
" "
645-
};
640+
641+
let next_line_specs = self.use_long && arg.is_some();
642+
if !spec_vals.is_empty() && !next_line_specs {
643+
if !help_is_empty {
644+
let sep = " ";
646645
help.push_str(sep);
647646
}
648647
help.push_str(spec_vals);
648+
help_is_empty = help.is_empty();
649649
}
650+
650651
let avail_chars = self.term_w.saturating_sub(spaces);
651652
debug!(
652653
"HelpTemplate::help: help_width={}, spaces={}, avail={}",
@@ -656,8 +657,8 @@ impl HelpTemplate<'_, '_> {
656657
);
657658
help.wrap(avail_chars);
658659
help.indent("", &trailing_indent);
659-
let help_is_empty = help.is_empty();
660660
self.writer.push_styled(&help);
661+
661662
if let Some(arg) = arg {
662663
if !arg.is_hide_possible_values_set() && self.use_long_pv(arg) {
663664
const DASH_SPACE: usize = "- ".len();
@@ -707,6 +708,19 @@ impl HelpTemplate<'_, '_> {
707708
}
708709
}
709710
}
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+
}
710724
}
711725

712726
/// 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)