Skip to content

Commit

Permalink
fix: doesn't print the argument sections in the help message if all a…
Browse files Browse the repository at this point in the history
…rgs in that section are hidden
  • Loading branch information
kbknapp committed Mar 4, 2017
1 parent 7b4000a commit ce5ee5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ impl<'a> Help<'a> {
#[cfg_attr(feature = "lints", allow(useless_let_if_seq))]
pub fn write_all_args(&mut self, parser: &Parser) -> ClapResult<()> {
debugln!("Help::write_all_args;");
let flags = parser.has_flags();
let pos = parser.has_positionals();
let opts = parser.has_opts();
let subcmds = parser.has_subcommands();
let flags = parser.has_visible_flags();
let pos = parser.has_visible_positionals();
let opts = parser.has_visible_opts();
let subcmds = parser.has_visible_subcommands();

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

Expand Down
24 changes: 24 additions & 0 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,30 @@ impl<'a, 'b> Parser<'a, 'b>
#[inline]
pub fn has_subcommands(&self) -> bool { !self.subcommands.is_empty() }

#[inline]
pub fn has_visible_opts(&self) -> bool {
if self.opts.is_empty() { return false; }
self.opts.iter().any(|o| !o.is_set(ArgSettings::Hidden))
}

#[inline]
pub fn has_visible_flags(&self) -> bool {
if self.flags.is_empty() { return false; }
self.flags.iter().any(|f| !f.is_set(ArgSettings::Hidden))
}

#[inline]
pub fn has_visible_positionals(&self) -> bool {
if self.positionals.is_empty() { return false; }
self.positionals.values().any(|p| !p.is_set(ArgSettings::Hidden))
}

#[inline]
pub fn has_visible_subcommands(&self) -> bool {
if self.subcommands.is_empty() { return false; }
self.subcommands.iter().any(|s| !s.is_set(AppSettings::Hidden))
}

#[inline]
pub fn is_set(&self, s: AS) -> bool { self.settings.is_set(s) }

Expand Down

0 comments on commit ce5ee5f

Please sign in to comment.