fix(help): don't show ARGS when there are only hidden positional args

Also no need to check for Hidden inside for that already is filtered
on !Hidden.

Closes #882
This commit is contained in:
Joost Yervante Damad 2017-03-03 09:32:09 +01:00 committed by Kevin K
parent 432837624c
commit 8adf353e0b
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
3 changed files with 8 additions and 9 deletions

View file

@ -195,9 +195,7 @@ impl<'a> Help<'a> {
if arg.longest_filter() { if arg.longest_filter() {
self.longest = cmp::max(self.longest, arg.to_string().len()); self.longest = cmp::max(self.longest, arg.to_string().len());
} }
if !arg.is_set(ArgSettings::Hidden) { arg_v.push(arg)
arg_v.push(arg)
}
} }
let mut first = true; let mut first = true;
for arg in arg_v { for arg in arg_v {
@ -541,7 +539,7 @@ impl<'a> Help<'a> {
pub fn write_all_args(&mut self, parser: &Parser) -> ClapResult<()> { pub fn write_all_args(&mut self, parser: &Parser) -> ClapResult<()> {
debugln!("Help::write_all_args;"); debugln!("Help::write_all_args;");
let flags = parser.has_flags(); let flags = parser.has_flags();
let pos = parser.has_positionals(); let pos = parser.positionals().filter(|arg| !arg.is_set(ArgSettings::Hidden)).count() > 0;
let opts = parser.has_opts(); let opts = parser.has_opts();
let subcmds = parser.has_subcommands(); let subcmds = parser.has_subcommands();

View file

@ -542,7 +542,7 @@ impl<'a, 'b> Parser<'a, 'b>
#[inline] #[inline]
pub fn has_positionals(&self) -> bool { !self.positionals.is_empty() } pub fn has_positionals(&self) -> bool { !self.positionals.is_empty() }
#[inline] #[inline]
pub fn has_subcommands(&self) -> bool { !self.subcommands.is_empty() } pub fn has_subcommands(&self) -> bool { !self.subcommands.is_empty() }

View file

@ -5,12 +5,12 @@ use clap::{App, Arg};
include!("../clap-test.rs"); include!("../clap-test.rs");
static HIDDEN_ARGS: &'static str = "test 1.3 static HIDDEN_ARGS: &'static str = "test 1.4
Kevin K. Kevin K.
tests stuff tests stuff
USAGE: USAGE:
test [FLAGS] [OPTIONS] test [FLAGS] [OPTIONS] [DUMMY]
FLAGS: FLAGS:
-F, --flag2 some other flag -F, --flag2 some other flag
@ -25,9 +25,10 @@ fn hidden_args() {
let app = App::new("test") let app = App::new("test")
.author("Kevin K.") .author("Kevin K.")
.about("tests stuff") .about("tests stuff")
.version("1.3") .version("1.4")
.args(&[Arg::from_usage("-f, --flag 'some flag'").hidden(true), .args(&[Arg::from_usage("-f, --flag 'some flag'").hidden(true),
Arg::from_usage("-F, --flag2 'some other flag'"), Arg::from_usage("-F, --flag2 'some other flag'"),
Arg::from_usage("--option [opt] 'some option'")]); Arg::from_usage("--option [opt] 'some option'"),
Arg::with_name("DUMMY").required(false).hidden(true)]);
assert!(test::compare_output(app, "test --help", HIDDEN_ARGS, false)); assert!(test::compare_output(app, "test --help", HIDDEN_ARGS, false));
} }