Skip to content

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

Merged
dearchap merged 7 commits intourfave:mainfrom
TimSoethout:main
Mar 1, 2026
Merged

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

Conversation

@TimSoethout
Copy link
Contributor

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>
@dearchap dearchap merged commit 65ded98 into urfave:main Mar 1, 2026
9 checks passed
Maks1mS pushed a commit to stplr-dev/stplr that referenced this pull request Mar 1, 2026
This PR contains the following updates:

| Package | Type | Update | Change | OpenSSF |
|---|---|---|---|---|
| [github.com/urfave/cli/v3](https://github.com/urfave/cli) | require | minor | `v3.6.2` → `v3.7.0` | [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/urfave/cli/badge)](https://securityscorecards.dev/viewer/?uri=github.com/urfave/cli) |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the Dependency Dashboard for more information.

---

### Release Notes

<details>
<summary>urfave/cli (github.com/urfave/cli/v3)</summary>

### [`v3.7.0`](https://github.com/urfave/cli/releases/tag/v3.7.0)

[Compare Source](urfave/cli@v3.6.2...v3.7.0)

#### What's Changed

- Fix: use the correct type name in the tracef message by [@&#8203;icholy](https://github.com/icholy) in [#&#8203;2251](urfave/cli#2251)
- chore(deps): bump mkdocs-git-revision-date-localized-plugin from 1.5.0 to 1.5.1 in the python-packages group by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2252](urfave/cli#2252)
- Fix:(issue\_2254) Fix incorrect handling of arg after short option token by [@&#8203;dearchap](https://github.com/dearchap) in [#&#8203;2255](urfave/cli#2255)
- feat: ShellComplete for fish by [@&#8203;marcusramberg](https://github.com/marcusramberg) in [#&#8203;2256](urfave/cli#2256)
- Fix: propagate MutuallyExclusiveFlags persistent flags to subcommands by [@&#8203;siutsin](https://github.com/siutsin) in [#&#8203;2266](urfave/cli#2266)
- feat: support dynamic fish completion by [@&#8203;Maks1mS](https://github.com/Maks1mS) in [#&#8203;2270](urfave/cli#2270)
- fix(help): show GLOBAL OPTIONS for leaf subcommands when HideHelpCommand is true by [@&#8203;TimSoethout](https://github.com/TimSoethout) in [#&#8203;2269](urfave/cli#2269)

#### New Contributors

- [@&#8203;marcusramberg](https://github.com/marcusramberg) made their first contribution in [#&#8203;2256](urfave/cli#2256)
- [@&#8203;siutsin](https://github.com/siutsin) made their first contribution in [#&#8203;2266](urfave/cli#2266)
- [@&#8203;TimSoethout](https://github.com/TimSoethout) made their first contribution in [#&#8203;2269](urfave/cli#2269)

**Full Changelog**: <urfave/cli@v3.6.2...v3.7.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At 12:00 AM through 04:59 AM and 10:00 PM through 11:59 PM, Monday through Friday ( * 0-4,22-23 * * 1-5 ), Only on Sunday and Saturday ( * * * * 0,6 ) (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNS4yIiwidXBkYXRlZEluVmVyIjoiNDMuMTUuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiS2luZC9EZXBlbmRlbmNpZXMiXX0=-->

Reviewed-on: https://altlinux.space/stapler/stplr/pulls/340
Co-authored-by: Renovate Bot <stapler-helper-bot@noreply.altlinux.space>
Co-committed-by: Renovate Bot <stapler-helper-bot@noreply.altlinux.space>
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

4 participants