Skip to content

Commit

Permalink
fix(help): Hide 'help' if only flattened subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 27, 2023
1 parent a9322ca commit b13f6d9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clap_builder/src/output/help_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clap_builder/src/output/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
5 changes: 0 additions & 5 deletions tests/builder/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3314,15 +3314,10 @@ fn flatten_single_hidden_command() {
parent command
Usage: parent [OPTIONS]
parent help [COMMAND]...
Options:
--parent <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)
Expand Down

0 comments on commit b13f6d9

Please sign in to comment.