From b13f6d98622b80ba30e63c2c6e65d218cc8a4de3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 27 Nov 2023 10:49:21 -0600 Subject: [PATCH] fix(help): Hide 'help' if only flattened subcommand --- clap_builder/src/output/help_template.rs | 2 +- clap_builder/src/output/usage.rs | 2 +- tests/builder/help.rs | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/clap_builder/src/output/help_template.rs b/clap_builder/src/output/help_template.rs index 8c719043500..9fe7211b306 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 6e27b160054..d75b704ba74 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 562d906c05f..5f413145018 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)