Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(help): Always trim output #4156

Merged
merged 1 commit into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- *(help)* Subcommands are now listed before arguments. To get the old behavior, see `Command::help_template`
- *(help)* Help headings are now title cased, making any user-provided help headings inconsistent. To get the old behavior, see `Command::help_template`, `Arg::help_heading`, and `Command::subcommand_help_heading`
- *(help)* "Command" is used as the section heading for subcommands and `COMMAND` for the value name. To get the old behavior, see `Command::subcommand_help_heading` and `Arg::subcommand_value_name`
- *(help)* Whitespace in help output is now trimmed to ensure consistency regardless of how well a template matches the users needs.
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag (#3776)
- *(derive)* Changed the default for arguments from `parse` to `value_parser`., removing `parse` support
- *(derive)* `subcommand_required(true).arg_required_else_help(true)` is set instead of `SubcommandRequiredElseHelp` (#3280)
Expand Down Expand Up @@ -99,6 +100,7 @@ Deprecated
- *(help)* Use `[positional]` in list when relevant (#4144)
- *(help)* Show all `[positional]` in usage
- *(help)* Polish up subcommands by referring to them as commands
- *(help)* Trim extra whitespace to avoid artifacts from different uses of templates
- *(version)* Use `Command::display_name` rather than `Command::bin_name`
- *(parser)* Assert on unknown args when using external subcommands (#3703)
- *(parser)* Always fill in `""` argument for external subcommands (#3263)
Expand Down
3 changes: 3 additions & 0 deletions src/output/help.rs
Expand Up @@ -106,6 +106,9 @@ impl<'cmd, 'writer> Help<'cmd, 'writer> {
self.write_templated_help(template);
}

// Remove any extra lines caused by book keeping
self.writer.trim();
// Ensure there is still a trailing newline
self.none("\n");
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/builder/help.rs
Expand Up @@ -1627,7 +1627,7 @@ Options:

NETWORKING:
-n, --no-proxy Do not use system proxy settings
--port
--port
";

let cmd = Command::new("blorp")
Expand Down Expand Up @@ -2853,7 +2853,7 @@ fn no_wrap_help() {
let cmd = Command::new("ctest")
.term_width(0)
.override_help(MULTI_SC_HELP);
utils::assert_output(cmd, "ctest --help", &format!("{}\n", MULTI_SC_HELP), false);
utils::assert_output(cmd, "ctest --help", MULTI_SC_HELP, false);
}

#[test]
Expand Down