Skip to content

Commit

Permalink
fix: Don't print 'OPTIONS' when all options are hidden for short help
Browse files Browse the repository at this point in the history
  • Loading branch information
thedadams committed Apr 16, 2020
1 parent 4c3a7f7 commit 0584b57
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/output/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,9 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
acc
}
}) > 0;
let opts = self.parser.has_opts();
let opts = opts!(self.parser.app)
.filter(|arg| should_show_arg(self.use_long, arg))
.collect::<Vec<_>>();
let subcmds = self.parser.has_visible_subcommands();

let custom_headings = self.parser.app.args.args.iter().fold(0, |acc, arg| {
Expand All @@ -654,7 +656,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {

let unified_help = self.parser.is_set(AppSettings::UnifiedHelpMessage);

if unified_help && (flags || opts) {
if unified_help && (flags || !opts.is_empty()) {
let opts_flags = self
.parser
.app
Expand All @@ -679,12 +681,12 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
self.write_args(&*flags_v)?;
first = false;
}
if opts {
if !opts.is_empty() {
if !first {
self.none("\n\n")?;
}
self.warning("OPTIONS:\n")?;
self.write_args(&*opts!(self.parser.app).collect::<Vec<_>>())?;
self.write_args(&opts)?;
first = false;
}
if custom_headings {
Expand Down
28 changes: 28 additions & 0 deletions tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,19 @@ FLAGS:
-h, --help Prints help information
-V, --version Prints version information";

static ISSUE_1364: &str = "demo
USAGE:
demo [FLAGS] [OPTIONS] [FILES]...
ARGS:
<FILES>...
FLAGS:
-f
-h, --help Prints help information
-V, --version Prints version information";

fn setup() -> App<'static> {
App::new("test")
.author("Kevin K.")
Expand Down Expand Up @@ -1587,6 +1600,21 @@ fn show_short_about_issue_897() {
));
}

#[test]
fn issue_1364_no_short_options() {
let app = App::new("demo")
.arg(Arg::with_name("foo").short('f'))
.arg(
Arg::with_name("baz")
.short('z')
.value_name("BAZ")
.hidden_short_help(true),
)
.arg(Arg::with_name("files").value_name("FILES").multiple(true));

assert!(utils::compare_output(app, "demo -h", ISSUE_1364, false));
}

#[rustfmt::skip]
#[test]
fn issue_1487() {
Expand Down

0 comments on commit 0584b57

Please sign in to comment.