From dfe9e73880b15f16c722e5681e4015265c42b678 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 7 Nov 2022 10:35:29 -0600 Subject: [PATCH] fix(help): Update auto-next-line to use new padding In clap v4, we changed the padding from 4 to 2 but we didn't update our calculation for when to switch to next-line-help as it was a magic number (we tried to catch all of these). When updating the tests, we also missed that a test was being wrapped too narrowly This was found while discussing #3300 --- src/output/help_template.rs | 8 ++++++-- tests/builder/help.rs | 19 ++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/output/help_template.rs b/src/output/help_template.rs index 7a3bdcf4dd1..3cf693fa880 100644 --- a/src/output/help_template.rs +++ b/src/output/help_template.rs @@ -689,7 +689,11 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { // force_next_line let h = arg.get_help().unwrap_or_default(); let h_w = h.display_width() + display_width(spec_vals); - let taken = longest + 12; + let taken = if arg.is_positional() { + longest + TAB_WIDTH * 2 + } else { + longest + TAB_WIDTH * 2 + 4 // See `fn short` for the 4 + }; self.term_w >= taken && (taken as f32 / self.term_w as f32) > 0.40 && h_w > (self.term_w - taken) @@ -925,7 +929,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { // force_next_line let h = cmd.get_about().unwrap_or_default(); let h_w = h.display_width() + display_width(spec_vals); - let taken = longest + 12; + let taken = longest + TAB_WIDTH * 2; self.term_w >= taken && (taken as f32 / self.term_w as f32) > 0.40 && h_w > (self.term_w - taken) diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 1bd8a2868e4..400085e53f7 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -355,17 +355,14 @@ fn wrapped_help() { Usage: test [OPTIONS] Options: - -a, --all - Also do versioning for private crates (will not be - published) - --exact - Specify inter dependency version numbers exactly with `=` - --no-git-commit - Do not commit version changes - --no-git-push - Do not push generated commit and tags to git remote - -h, --help - Print help information + -a, --all Also do versioning for private crates (will + not be published) + --exact Specify inter dependency version numbers + exactly with `=` + --no-git-commit Do not commit version changes + --no-git-push Do not push generated commit and tags to git + remote + -h, --help Print help information "; let cmd = Command::new("test") .term_width(67)