-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: inherit HideHelpCommand in subcommands #2395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,14 +227,25 @@ func (cmd *Command) hideHelp() bool { | |
| return false | ||
| } | ||
|
|
||
| func (cmd *Command) hideHelpCommand() bool { | ||
| tracef("hide help command (cmd=%[1]q)", cmd.Name) | ||
| for c := cmd; c != nil; c = c.parent { | ||
| if c.HideHelpCommand { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| func (cmd *Command) ensureHelp() { | ||
| tracef("ensuring help (cmd=%[1]q)", cmd.Name) | ||
|
|
||
| helpCommand := buildHelpCommand(true) | ||
|
|
||
| if !cmd.hideHelp() { | ||
| if cmd.Command(helpCommand.Name) == nil { | ||
| if !cmd.HideHelpCommand { | ||
| if !cmd.hideHelpCommand() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heads-up: this is a behavior change for nested trees, not just a bug fix. |
||
| tracef("appending helpCommand (cmd=%[1]q)", cmd.Name) | ||
| cmd.appendCommand(helpCommand) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: with this change
HideHelpCommandnow propagates to all descendants, but its doc comment incommand.gostill reads// Ignored if HideHelp is true.only. A short note that the value applies to this command and its subcommands would prevent confusion about why a nested command lost itshelpcommand.