From 58b5bd89ea1dc324769f4b6185ca840d775bb66e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jul 2024 16:03:39 -0500 Subject: [PATCH 1/2] test(help): Show bad subcommand wrapping --- tests/builder/help.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 0169bb28538..50027e058cc 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -566,10 +566,20 @@ 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 @@ -614,10 +624,20 @@ 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 From 360bb3bc11bf7a0a18ba269642704492383eb028 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jul 2024 16:16:52 -0500 Subject: [PATCH 2/2] fix(help): Properly wrap subcommand about Fixes #5607 --- clap_builder/src/output/help_template.rs | 2 +- tests/builder/help.rs | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clap_builder/src/output/help_template.rs b/clap_builder/src/output/help_template.rs index f3a2b02ed33..3abeab1487a 100644 --- a/clap_builder/src/output/help_template.rs +++ b/clap_builder/src/output/help_template.rs @@ -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 diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 50027e058cc..fb203b0e59e 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -577,9 +577,8 @@ 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) + 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 @@ -635,9 +634,8 @@ 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) + 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