Skip to content

fix: show help for the whole subcommand path given to help - #2520

Merged
coilysiren merged 1 commit into
urfave:mainfrom
10kartik:help-nested-path
Nov 1, 2026
Merged

coilysiren merged 1 commit into
urfave:mainfrom
10kartik:help-nested-path

Conversation

@10kartik

@10kartik 10kartik commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

app help foo bar shows the help of foo, not of its subcommand bar, and silently ignores bar. The same goes for app -h foo bar. Only app foo help bar reaches bar:

cmd := &cli.Command{
	Name: "app",
	Commands: []*cli.Command{
		{Name: "cmd", Commands: []*cli.Command{{Name: "subcmd", Usage: "runs subcmd"}}},
	},
}
$ app help cmd subcmd
NAME:
   app cmd - ...        <- cmd's help, not subcmd's

helpCommandAction only looked at the first arg. It now follows the args down as long as each one names a subcommand of the previous one, aliases included, and shows the help of the last match. An arg that isn't a subcommand stops the walk, so app help cmd nope still shows cmd's help, as it does today.

Which issue(s) this PR fixes:

None, found while checking help output for nested commands.

Testing

  • New TestHelpCommand_NestedPath covers help cmd subcmd, an alias in the path, -h cmd subcmd, and help cmd nope. The first three fail on main; the last passes before and after.
  • make generate vet check-binary-size and make v3diff pass, with no API change. go test -race ./... passes, as do the tests with urfave_cli_no_template, urfave_cli_no_docs and urfave_cli_no_suggest.

The change and the test were written with Claude Code (AI).

Release Notes

`help` and `--help` now show the help of the last subcommand in a path such as `app help foo bar`, instead of stopping at the first.

🤖 Generated with Claude Code

`app help foo bar` showed the help of foo and ignored bar. The help
command and the help flag now follow the args down as long as they
name subcommands, so it shows bar's help, like `app foo help bar`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@10kartik
10kartik requested a review from a team as a code owner November 1, 2026 15:00

@coilysiren coilysiren left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@coilysiren
coilysiren merged commit 431e2dc into urfave:main Nov 1, 2026
9 checks passed
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.

2 participants