File tree Expand file tree Collapse file tree 4 files changed +47
-2
lines changed
Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ var AnyArguments = []Argument{
5757}
5858 AnyArguments to differentiate between no arguments(nil) vs aleast one
5959
60+ var ArgsUsageCommandHelp = "[command]"
61+ ArgsUsageCommandHelp is a short description of the arguments of the help
62+ command
63+
6064var CommandHelpTemplate = `NAME:
6165 {{template "helpNameTemplate" .}}
6266
@@ -172,6 +176,10 @@ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
172176 cli.go uses text/template to render templates. You can render custom help
173177 text by setting this variable.
174178
179+ var UsageCommandHelp = "Shows a list of commands or help for one command"
180+ UsageCommandHelp is the text to override the USAGE section of the help
181+ command
182+
175183var VersionPrinter = DefaultPrintVersion
176184 VersionPrinter prints the version for the root Command.
177185
Original file line number Diff line number Diff line change @@ -56,12 +56,18 @@ var ShowCommandHelp = DefaultShowCommandHelp
5656// ShowSubcommandHelp prints help for the given subcommand
5757var ShowSubcommandHelp = DefaultShowSubcommandHelp
5858
59+ // UsageCommandHelp is the text to override the USAGE section of the help command
60+ var UsageCommandHelp = "Shows a list of commands or help for one command"
61+
62+ // ArgsUsageCommandHelp is a short description of the arguments of the help command
63+ var ArgsUsageCommandHelp = "[command]"
64+
5965func buildHelpCommand (withAction bool ) * Command {
6066 cmd := & Command {
6167 Name : helpName ,
6268 Aliases : []string {helpAlias },
63- Usage : "Shows a list of commands or help for one command" ,
64- ArgsUsage : "[command]" ,
69+ Usage : UsageCommandHelp ,
70+ ArgsUsage : ArgsUsageCommandHelp ,
6571 HideHelp : true ,
6672 }
6773
Original file line number Diff line number Diff line change @@ -2010,3 +2010,26 @@ func TestPrintHelpCustomTemplateError(t *testing.T) {
20102010 * tmpl = oldtmpl
20112011 }
20122012}
2013+
2014+ func TestCustomUsageCommandHelp (t * testing.T ) {
2015+ old := UsageCommandHelp
2016+ defer func () { UsageCommandHelp = old }()
2017+
2018+ UsageCommandHelp = "Custom usage help command"
2019+
2020+ out := & bytes.Buffer {}
2021+ cmd := & Command {
2022+ Name : "app" ,
2023+ Commands : []* Command {
2024+ {
2025+ Name : "cmd" ,
2026+ Commands : []* Command {{Name : "subcmd" }},
2027+ },
2028+ },
2029+ Writer : out ,
2030+ ErrWriter : out ,
2031+ }
2032+
2033+ _ = cmd .Run (buildTestContext (t ), []string {"app" , "help" })
2034+ assert .Contains (t , out .String (), UsageCommandHelp )
2035+ }
Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ var AnyArguments = []Argument{
5757}
5858 AnyArguments to differentiate between no arguments(nil) vs aleast one
5959
60+ var ArgsUsageCommandHelp = "[command]"
61+ ArgsUsageCommandHelp is a short description of the arguments of the help
62+ command
63+
6064var CommandHelpTemplate = `NAME:
6165 {{template "helpNameTemplate" .}}
6266
@@ -172,6 +176,10 @@ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
172176 cli.go uses text/template to render templates. You can render custom help
173177 text by setting this variable.
174178
179+ var UsageCommandHelp = "Shows a list of commands or help for one command"
180+ UsageCommandHelp is the text to override the USAGE section of the help
181+ command
182+
175183var VersionPrinter = DefaultPrintVersion
176184 VersionPrinter prints the version for the root Command.
177185
You can’t perform that action at this time.
0 commit comments