diff --git a/godoc-current.txt b/godoc-current.txt index c6f50b2eaf..9784c4e2b3 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -57,6 +57,10 @@ var AnyArguments = []Argument{ } AnyArguments to differentiate between no arguments(nil) vs aleast one +var ArgsUsageCommandHelp = "[command]" + ArgsUsageCommandHelp is a short description of the arguments of the help + command + var CommandHelpTemplate = `NAME: {{template "helpNameTemplate" .}} @@ -172,6 +176,10 @@ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} cli.go uses text/template to render templates. You can render custom help text by setting this variable. +var UsageCommandHelp = "Shows a list of commands or help for one command" + UsageCommandHelp is the text to override the USAGE section of the help + command + var VersionPrinter = DefaultPrintVersion VersionPrinter prints the version for the root Command. diff --git a/help.go b/help.go index 028fbb5dbb..78686b1422 100644 --- a/help.go +++ b/help.go @@ -56,12 +56,18 @@ var ShowCommandHelp = DefaultShowCommandHelp // ShowSubcommandHelp prints help for the given subcommand var ShowSubcommandHelp = DefaultShowSubcommandHelp +// UsageCommandHelp is the text to override the USAGE section of the help command +var UsageCommandHelp = "Shows a list of commands or help for one command" + +// ArgsUsageCommandHelp is a short description of the arguments of the help command +var ArgsUsageCommandHelp = "[command]" + func buildHelpCommand(withAction bool) *Command { cmd := &Command{ Name: helpName, Aliases: []string{helpAlias}, - Usage: "Shows a list of commands or help for one command", - ArgsUsage: "[command]", + Usage: UsageCommandHelp, + ArgsUsage: ArgsUsageCommandHelp, HideHelp: true, } diff --git a/help_test.go b/help_test.go index 6944c1b1b1..0f7f5d5981 100644 --- a/help_test.go +++ b/help_test.go @@ -2009,3 +2009,26 @@ func TestPrintHelpCustomTemplateError(t *testing.T) { *tmpl = oldtmpl } } + +func TestCustomUsageCommandHelp(t *testing.T) { + old := UsageCommandHelp + defer func() { UsageCommandHelp = old }() + + UsageCommandHelp = "Custom usage help command" + + out := &bytes.Buffer{} + cmd := &Command{ + Name: "app", + Commands: []*Command{ + { + Name: "cmd", + Commands: []*Command{{Name: "subcmd"}}, + }, + }, + Writer: out, + ErrWriter: out, + } + + _ = cmd.Run(buildTestContext(t), []string{"app", "help"}) + assert.Contains(t, out.String(), UsageCommandHelp) +} diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt index c6f50b2eaf..9784c4e2b3 100644 --- a/testdata/godoc-v3.x.txt +++ b/testdata/godoc-v3.x.txt @@ -57,6 +57,10 @@ var AnyArguments = []Argument{ } AnyArguments to differentiate between no arguments(nil) vs aleast one +var ArgsUsageCommandHelp = "[command]" + ArgsUsageCommandHelp is a short description of the arguments of the help + command + var CommandHelpTemplate = `NAME: {{template "helpNameTemplate" .}} @@ -172,6 +176,10 @@ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} cli.go uses text/template to render templates. You can render custom help text by setting this variable. +var UsageCommandHelp = "Shows a list of commands or help for one command" + UsageCommandHelp is the text to override the USAGE section of the help + command + var VersionPrinter = DefaultPrintVersion VersionPrinter prints the version for the root Command.