Skip to content

Commit ce5ee5f

Browse files
committed
fix: doesn't print the argument sections in the help message if all args in that section are hidden
1 parent 7b4000a commit ce5ee5f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/app/help.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,10 @@ impl<'a> Help<'a> {
540540
#[cfg_attr(feature = "lints", allow(useless_let_if_seq))]
541541
pub fn write_all_args(&mut self, parser: &Parser) -> ClapResult<()> {
542542
debugln!("Help::write_all_args;");
543-
let flags = parser.has_flags();
544-
let pos = parser.has_positionals();
545-
let opts = parser.has_opts();
546-
let subcmds = parser.has_subcommands();
543+
let flags = parser.has_visible_flags();
544+
let pos = parser.has_visible_positionals();
545+
let opts = parser.has_visible_opts();
546+
let subcmds = parser.has_visible_subcommands();
547547

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

src/app/parser.rs

+24
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,30 @@ impl<'a, 'b> Parser<'a, 'b>
555555
#[inline]
556556
pub fn has_subcommands(&self) -> bool { !self.subcommands.is_empty() }
557557

558+
#[inline]
559+
pub fn has_visible_opts(&self) -> bool {
560+
if self.opts.is_empty() { return false; }
561+
self.opts.iter().any(|o| !o.is_set(ArgSettings::Hidden))
562+
}
563+
564+
#[inline]
565+
pub fn has_visible_flags(&self) -> bool {
566+
if self.flags.is_empty() { return false; }
567+
self.flags.iter().any(|f| !f.is_set(ArgSettings::Hidden))
568+
}
569+
570+
#[inline]
571+
pub fn has_visible_positionals(&self) -> bool {
572+
if self.positionals.is_empty() { return false; }
573+
self.positionals.values().any(|p| !p.is_set(ArgSettings::Hidden))
574+
}
575+
576+
#[inline]
577+
pub fn has_visible_subcommands(&self) -> bool {
578+
if self.subcommands.is_empty() { return false; }
579+
self.subcommands.iter().any(|s| !s.is_set(AppSettings::Hidden))
580+
}
581+
558582
#[inline]
559583
pub fn is_set(&self, s: AS) -> bool { self.settings.is_set(s) }
560584

0 commit comments

Comments
 (0)