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 @@ -2009,3 +2009,26 @@ func TestPrintHelpCustomTemplateError(t *testing.T) {
20092009 * tmpl = oldtmpl
20102010 }
20112011}
2012+
2013+ func TestCustomUsageCommandHelp (t * testing.T ) {
2014+ old := UsageCommandHelp
2015+ defer func () { UsageCommandHelp = old }()
2016+
2017+ UsageCommandHelp = "Custom usage help command"
2018+
2019+ out := & bytes.Buffer {}
2020+ cmd := & Command {
2021+ Name : "app" ,
2022+ Commands : []* Command {
2023+ {
2024+ Name : "cmd" ,
2025+ Commands : []* Command {{Name : "subcmd" }},
2026+ },
2027+ },
2028+ Writer : out ,
2029+ ErrWriter : out ,
2030+ }
2031+
2032+ _ = cmd .Run (buildTestContext (t ), []string {"app" , "help" })
2033+ assert .Contains (t , out .String (), UsageCommandHelp )
2034+ }
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