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): Don't accidentally show long help with --help when it isn't intended. #4712

Merged
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
7 changes: 4 additions & 3 deletions src/builder/command.rs
Expand Up @@ -4597,9 +4597,10 @@ impl Command {
&& (v.get_long_help().is_some()
|| v.is_hide_long_help_set()
|| v.is_hide_short_help_set()
|| v.get_possible_values()
.iter()
.any(PossibleValue::should_show_help))
|| (!v.is_hide_possible_values_set()
&& v.get_possible_values()
.iter()
.any(PossibleValue::should_show_help)))
};

// Subcommands aren't checked because we prefer short help for them, deferring to
Expand Down
23 changes: 23 additions & 0 deletions tests/builder/help.rs
Expand Up @@ -676,6 +676,29 @@ Options:
utils::assert_output(app, "ctest --help", POS_VALS_HELP, false);
}

#[test]
fn hidden_possible_vals() {
static POS_VALS_HELP: &str = "\
Usage: ctest [pos]

Arguments:
[pos]

Options:
-h, --help Print help
";
let app = Command::new("ctest").arg(
Arg::new("pos")
.hide_possible_values(true)
.value_parser([
PossibleValue::new("fast"),
PossibleValue::new("slow").help("not as fast"),
])
.action(ArgAction::Set),
);
utils::assert_output(app, "ctest --help", POS_VALS_HELP, false);
}

#[test]
#[cfg(feature = "wrap_help")]
fn issue_626_panic() {
Expand Down