Skip to content

Made command help more consistent#2287

Open
markshep-wbg wants to merge 4 commits intourfave:mainfrom
markshep-wbg:fix-command-help
Open

Made command help more consistent#2287
markshep-wbg wants to merge 4 commits intourfave:mainfrom
markshep-wbg:fix-command-help

Conversation

@markshep-wbg
Copy link

What type of PR is this?

  • bug

What this PR does / why we need it:

I was trying to customize the help in my app by setting the following to custom functions:

  • cli.ShowRootCommandHelp
  • cli.ShowCommandHelp
  • cli.ShowSubcommandHelp

However I noticed that in the particular case of app command help none of these were getting called and I was getting the builtin help. Looking in the code the help.helpCommandAction() function wasn't calling any of the above custom functions in the "Case 3, 5" branch and directly called HelpPrinter() instead. So I fixed this in commit 4031d4c by making it call ShowCommandHelp() with appropriate arguments.

The TestCommand_Run_SubcommandFullPath test then started failing because it wasn't getting the [options] part of the help text (which is in usageTemplate). I fixed that in commit 27816c3 by changing the test for which template to use to check for visible commands rather than any commands. This test now matches the code that was removed in the previous commit.

Then there were two test failures in:

  • TestShowCommandHelp_HelpPrinterCustom/standard_command
  • ExampleCommand_Run_commandHelp

After looking at those I came to the conclusion that the help text now getting output was more correct than before, so I fixed the expected test results to match reality in commit 159faa0. In both cases new text includes the [options] text and a GLOBAL OPTIONS section, which seems appropriate as they're leaf commands that can be executed directly rather needing an additional subcommand to be specified.

Which issue(s) this PR fixes:

None - I didn't file a bug report, I just fixed it instead.

Testing

I ran make test locally.

Release Notes

* Help output is now more consistent with `cli.ShowCommandHelp` called in more places than before:
   * Sometimes it was being bypassed and the built-in help was directly called
   * Sometimes `cli.ShowSubcommandHelp` was being called instead

@markshep-wbg markshep-wbg requested a review from a team as a code owner March 20, 2026 01:14
@abitrolly
Copy link
Contributor

wasn't calling any of the above custom functions in the "Case 3, 5" branch

What is the "Case 3, 5" branch? Is there a diagram?

@markshep-wbg
Copy link
Author

What is the "Case 3, 5" branch? Is there a diagram?

I mean this "if" section: https://github.com/urfave/cli/blob/main/help.go#L126-L138

@dearchap
Copy link
Contributor

@abitrolly https://github.com/urfave/cli/blob/main/help.go#L87

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.

3 participants