fix: Don't print 'OPTIONS' when all options are hidden for short help

This commit is contained in:
Donnie Adams 2020-04-16 08:21:41 -07:00
parent 4c3a7f7998
commit 0584b57f29
2 changed files with 34 additions and 4 deletions

View file

@ -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| {
@ -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
@ -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 {

View file

@ -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.")
@ -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() {