Skip to content

fix: resolve remaining help invocation inconsistencies#2361

Merged
dearchap merged 5 commits into
urfave:mainfrom
dearchap:fix/remaining-help-inconsistencies
Jun 14, 2026
Merged

fix: resolve remaining help invocation inconsistencies#2361
dearchap merged 5 commits into
urfave:mainfrom
dearchap:fix/remaining-help-inconsistencies

Conversation

@dearchap

@dearchap dearchap commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug
  • cleanup

What this PR does / why we need it:

Fixes four remaining help invocation inconsistencies:

  1. Built-in help command identity — Added builtInHelp field to distinguish the built-in help command from user-defined commands named "help" or "h", preventing helpCommandAction from incorrectly matching user commands.

  2. "Incorrect Usage" prefix for required flags / mutually exclusive errors — Parse errors printed the prefix but required flag and mutually exclusive errors did not. Now consistent.

  3. Wrong help template for leaf commands on error — Required flag / mutex error paths used ShowSubcommandHelp which always uses SubcommandHelpTemplate, even for leaf commands. Now use ShowCommandHelp(ctx, cmd.parent, cmd.Name) which correctly selects CommandHelpTemplate (with OPTIONS) for leaf commands.

  4. Parse error help lookup was broken for subcommandsShowCommandHelp(ctx, cmd, cmd.Name) searched cmd in its own Commands (always failing). Fixed to ShowCommandHelp(ctx, cmd.parent, cmd.Name).

  5. checkAllRequiredFlags uses cmd.builtInHelp instead of fragile cmd.Name == helpName check.

Which issue(s) this PR fixes:

Related to #2126

Testing

All existing tests pass.

Help output for required flag and mutually exclusive flag errors now shows the correct template and includes the "Incorrect Usage" prefix.

- Add builtInHelp marker to distinguish the built-in help command
  from user-defined commands with the same name
- Fix helpCommandAction to use builtInHelp instead of name matching
- Fix checkAllRequiredFlags to use builtInHelp instead of name matching
- Add 'Incorrect Usage' prefix to required flag and mutually exclusive
  flag error paths for consistency with parse error handling
- Fix template selection for error paths: use ShowCommandHelp (via
  parent) instead of ShowSubcommandHelp, so leaf commands get
  CommandHelpTemplate with their OPTIONS section shown
- Fix parse error path (Path D) subcommand case: look up help from
  parent.Commands instead of cmd.Commands, which was always failing
@dearchap dearchap requested a review from a team as a code owner June 8, 2026 01:59
@dearchap dearchap merged commit 213b98c into urfave:main Jun 14, 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