Skip to content

fix(help): show GLOBAL OPTIONS for leaf subcommands when HideHelpCommand is true#2269

Open
TimSoethout wants to merge 7 commits intourfave:mainfrom
TimSoethout:main
Open

fix(help): show GLOBAL OPTIONS for leaf subcommands when HideHelpCommand is true#2269
TimSoethout wants to merge 7 commits intourfave:mainfrom
TimSoethout:main

Conversation

@TimSoethout
Copy link

What type of PR is this?

(REQUIRED)

bug

What this PR does / why we need it:

(REQUIRED)

This PR fixes a help-rendering edge case where enabling HideHelpCommand: true on a parent command caused leaf subcommand help to omit GLOBAL OPTIONS.

[help.go](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/)
    Updates [helpCommandAction](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/) leaf-command detection to use visible commands ([len(cmd.VisibleCommands()) == 0](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/)) instead of raw command count logic affected by the internal help command injection.
    Ensures leaf subcommands consistently render with [CommandHelpTemplate](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/), which includes GLOBAL OPTIONS.
[help_test.go](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/)
    Adds [TestShowSubcommandHelp_GlobalOptions_HideHelpCommand](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/), modeled after [TestShowSubcommandHelp_GlobalOptions](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/).
    Verifies subcommand help still shows inherited persistent/root flags when [HideHelpCommand](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/) is enabled.

Decision rationale:

This keeps existing template responsibilities intact and fixes the root cause (incorrect leaf-command detection), rather than duplicating template sections or altering unrelated help output paths.

Which issue(s) this PR fixes:

(REQUIRED)

Fixes #2268
Special notes for your reviewer:

(fill-in or delete this section)

Review focus: the [helpCommandAction](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/) branch that chooses command vs subcommand help template for case 3/5 flows.
The change is intentionally minimal and scoped to template selection logic plus regression coverage.

Testing

(fill-in or delete this section)

Added regression test:
    [TestShowSubcommandHelp_GlobalOptions_HideHelpCommand](https://automatic-succotash-xgp6xrq4r3p4qr.github.dev/)
Targeted verification:
    go test ./... -run 'TestShowSubcommandHelp_GlobalOptions(_HideHelpCommand)?$'
Full suite verification:
    go test [workspaces](http://_vscodecontentref_/11).

Release Notes

(REQUIRED)

Fix subcommand help output when HideHelpCommand is enabled so GLOBAL OPTIONS remain visible for leaf subcommands.

…elp-command

fix(help): show GLOBAL OPTIONS for leaf subcommands when HideHelpCommand is true
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a help-rendering edge case in helpCommandAction where leaf subcommand help could omit GLOBAL OPTIONS when a parent command sets HideHelpCommand: true, by basing “leaf command” detection on visible subcommands rather than raw cmd.Commands length (which can be affected by internal help command injection).

Changes:

  • Update leaf-command detection in helpCommandAction to use len(cmd.VisibleCommands()) == 0.
  • Add a regression test to ensure leaf subcommand help still includes GLOBAL OPTIONS when HideHelpCommand is enabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
help.go Fixes leaf detection for template selection by using visible subcommands, avoiding reliance on injected/hidden help commands.
help_test.go Adds regression coverage for the HideHelpCommand case to ensure GLOBAL OPTIONS are rendered for leaf subcommands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI and others added 5 commits February 26, 2026 19:31
…e fix

Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com>
Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com>
* Initial plan

* Restore docs/go.mod and docs/go.sum to original content

Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HideHelpCommand: true on a parent command causes missing GLOBAL OPTIONS in subcommand

3 participants