Skip to content

Commit

Permalink
fix(help): Update auto-next-line to use new padding
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epage committed Nov 7, 2022
1 parent 539577d commit dfe9e73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/output/help_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 8 additions & 11 deletions tests/builder/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dfe9e73

Please sign in to comment.