diff --git a/clap_builder/src/output/help_template.rs b/clap_builder/src/output/help_template.rs index 8c719043..9fe7211b 100644 --- a/clap_builder/src/output/help_template.rs +++ b/clap_builder/src/output/help_template.rs @@ -476,7 +476,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } } } - if flatten { + if subcmds && flatten { let mut cmd = self.cmd.clone(); cmd.build(); self.write_flat_subcommands(&cmd, &mut first); diff --git a/clap_builder/src/output/usage.rs b/clap_builder/src/output/usage.rs index 6e27b160..d75b704b 100644 --- a/clap_builder/src/output/usage.rs +++ b/clap_builder/src/output/usage.rs @@ -103,7 +103,7 @@ impl<'cmd> Usage<'cmd> { debug!("Usage::write_help_usage"); use std::fmt::Write; - if self.cmd.is_flatten_help_set() { + if self.cmd.has_visible_subcommands() && self.cmd.is_flatten_help_set() { if !self.cmd.is_subcommand_required_set() || self.cmd.is_args_conflicts_with_subcommands_set() { diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 562d906c..5f413145 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -3314,15 +3314,10 @@ fn flatten_single_hidden_command() { parent command Usage: parent [OPTIONS] - parent help [COMMAND]... Options: --parent -h, --help Print help - -parent help: -Print this message or the help of the given subcommand(s) - [COMMAND]... Print help for the subcommand(s) "; let cmd = Command::new("parent") .flatten_help(true)