Skip to content

Commit

Permalink
Merge pull request #5615 from epage/wrap
Browse files Browse the repository at this point in the history
fix(help): Properly wrap subcommand about
  • Loading branch information
epage authored Jul 31, 2024
2 parents e1f6320 + 360bb3b commit e19469f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clap_builder/src/output/help_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {

let spaces = if next_line_help {
TAB.len() + NEXT_LINE_INDENT.len()
} else if let Some(true) = arg.map(|a| a.is_positional()) {
} else if arg.map(|a| a.is_positional()).unwrap_or(true) {
longest + TAB_WIDTH * 2
} else {
longest + TAB_WIDTH * 2 + 4 // See `fn short` for the 4
Expand Down
22 changes: 20 additions & 2 deletions tests/builder/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,19 @@ fn wrapped_help() {
.long("no-git-push")
.action(ArgAction::SetTrue)
.help("Do not push generated commit and tags to git remote"),
)
.subcommand(
Command::new("sub1")
.about("One two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen")
);

let expected = str![[r#"
Usage: test [OPTIONS]
Usage: test [OPTIONS] [COMMAND]
Commands:
sub1 One two three four five six seven eight nine ten eleven
twelve thirteen fourteen fifteen
help Print this message or the help of the given subcommand(s)
Options:
-a, --all Also do versioning for private crates (will
Expand Down Expand Up @@ -614,10 +623,19 @@ fn unwrapped_help() {
.long("no-git-push")
.action(ArgAction::SetTrue)
.help("Do not push generated commit and tags to git remote"),
)
.subcommand(
Command::new("sub1")
.about("One two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen")
);

let expected = str![[r#"
Usage: test [OPTIONS]
Usage: test [OPTIONS] [COMMAND]
Commands:
sub1 One two three four five six seven eight nine ten eleven
twelve thirteen fourteen fifteen
help Print this message or the help of the given subcommand(s)
Options:
-a, --all Also do versioning for private crates (will
Expand Down

0 comments on commit e19469f

Please sign in to comment.