cli
cli copied to clipboard
Custom SubcommandHelpTemplate
Is there a way to set a custom help template for subcommands?
I know it's totally possible to set custom templates for the app (CustomAppHelpTemplate) and for commands (CustomHelpTemplate) but I can't find how to override the SubcommandHelpTemplate. What am I missing?
Jesus Christ, I just spent an hour in the VS Code Debugger trying to figure out why my CustomHelpTemplate
Template is not being printed correctly. The issue is here
https://github.com/urfave/cli/blob/master/app.go#L391
a
is a new *cli.App
that contains all configs for the command being executed, but it is not passed to checkSubcommandHelp, so when this if logic:
https://github.com/urfave/cli/blob/12b7dfd08cb0cf2853ce3aa0767046e1c4edaf23/help.go#L330
returns true indicating that the help text should be returned, and ShowSubcommandHelp
is called, c *cli.Context
is empty. Well not empty, not nil, but all of the properties are initialized with their default values.
https://github.com/urfave/cli/blob/12b7dfd08cb0cf2853ce3aa0767046e1c4edaf23/help.go#L224
So it doesn't matter what happens inside of ShowSubcommandHelp
, when the subsequent ShowCommandHelp
is called
https://github.com/urfave/cli/blob/12b7dfd08cb0cf2853ce3aa0767046e1c4edaf23/help.go#L189
command == ""
will always return true, and this is where our CustomHelpTemplate
value that is set on the *cli.Command
struct is ignored.
I am still digging to see if I can fix this, i've never put a PR into an Open Source project fixing a bug like this before. It's always been to fix typo's, etc.....
Yeah I have no clue what to do here, well "properly". I can see the data in the *cli.App
that is in the *cli.Context
here:
The issue is that the Name that is being passed to ShowCommandHelp
is bare because when RunAsSubcommand
is called, that calls NewContext
, this func initializes the Command as a &cli.Command
instead of the command that is housing the Subcommands.
https://github.com/urfave/cli/blob/12b7dfd08cb0cf2853ce3aa0767046e1c4edaf23/context.go#L33
Okay, I've put a PR in for this. I do not consider this an ideal fix, but it works.
@ddouglas Can you check if latest release solves this issue for you ?