Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" .}}

Expand Down Expand Up @@ -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.

Expand Down
10 changes: 8 additions & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
23 changes: 23 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions testdata/godoc-v3.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" .}}

Expand Down Expand Up @@ -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.

Expand Down