Merge pull request #2534 from stevenengler/hide-heading

Hide help heading when all args are hidden
This commit is contained in:
Pavan Kumar Sunkara 2021-08-12 21:32:07 +01:00 committed by GitHub
commit 8f2ba607aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 6 deletions

View file

@ -858,10 +858,6 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
} }
if !custom_headings.is_empty() { if !custom_headings.is_empty() {
for heading in custom_headings { for heading in custom_headings {
if !first {
self.none("\n\n")?;
}
self.warning(&*format!("{}:\n", heading))?;
let args = self let args = self
.parser .parser
.app .app
@ -873,9 +869,17 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
} }
false false
}) })
.filter(|arg| should_show_arg(self.use_long, arg))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
self.write_args(&*args)?;
first = false if !args.is_empty() {
if !first {
self.none("\n\n")?;
}
self.warning(&*format!("{}:\n", heading))?;
self.write_args(&*args)?;
first = false
}
} }
} }
} }

View file

@ -1944,6 +1944,64 @@ fn multiple_custom_help_headers() {
)); ));
} }
static CUSTOM_HELP_SECTION_HIDDEN_ARGS: &str = "blorp 1.4
Will M.
does stuff
USAGE:
test --song <song> --song-volume <volume>
FLAGS:
-h, --help Print help information
-V, --version Print version information
SPECIAL:
-b, --song <song> Change which song is played for birthdays
-v, --song-volume <volume> Change the volume of the birthday song";
#[test]
fn custom_help_headers_hidden_args() {
let app = App::new("blorp")
.author("Will M.")
.about("does stuff")
.version("1.4")
.help_heading("NETWORKING")
.arg(
Arg::new("no-proxy")
.short('n')
.long("no-proxy")
.about("Do not use system proxy settings")
.hidden_short_help(true),
)
.help_heading("SPECIAL")
.arg(
Arg::from("-b, --song <song> 'Change which song is played for birthdays'")
.help_heading(Some("IGNORE THIS")),
)
.stop_custom_headings()
.arg(
Arg::from("-v --song-volume <volume> 'Change the volume of the birthday song'")
.help_heading(Some("SPECIAL")),
)
.arg(
Arg::new("server-addr")
.short('a')
.long("server-addr")
.about("Set server address")
.help_heading(Some("NETWORKING"))
.hidden_short_help(true),
);
assert!(utils::compare_output(
app,
"test -h",
CUSTOM_HELP_SECTION_HIDDEN_ARGS,
false
));
}
static ISSUE_897: &str = "ctest-foo 0.1 static ISSUE_897: &str = "ctest-foo 0.1
Long about foo Long about foo