Merge pull request #1054 from itchyny/subcommand-consistent-description

Fix description of subcommand more consistent
main
lynn [they] 5 years ago committed by GitHub
commit ffbb8c04e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1567,7 +1567,8 @@ func TestApp_Run_CommandSubcommandHelpName(t *testing.T) {
} }
cmd := &Command{ cmd := &Command{
Name: "foo", Name: "foo",
Description: "foo commands", Usage: "foo commands",
Description: "This is a description",
Subcommands: []*Command{subCmd}, Subcommands: []*Command{subCmd},
} }
app.Commands = []*Command{cmd} app.Commands = []*Command{cmd}
@ -1584,6 +1585,11 @@ func TestApp_Run_CommandSubcommandHelpName(t *testing.T) {
t.Errorf("expected %q in output: %q", expected, output) t.Errorf("expected %q in output: %q", expected, output)
} }
expected = "DESCRIPTION:\n This is a description\n"
if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %q", expected, output)
}
expected = "base foo command [command options] [arguments...]" expected = "base foo command [command options] [arguments...]"
if !strings.Contains(output, expected) { if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %q", expected, output) t.Errorf("expected %q in output: %q", expected, output)

@ -56,10 +56,13 @@ OPTIONS:
// cli.go uses text/template to render templates. You can // cli.go uses text/template to render templates. You can
// render custom help text by setting this variable. // render custom help text by setting this variable.
var SubcommandHelpTemplate = `NAME: var SubcommandHelpTemplate = `NAME:
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} {{.HelpName}} - {{.Usage}}
USAGE: USAGE:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
DESCRIPTION:
{{.Description}}{{end}}
COMMANDS:{{range .VisibleCategories}}{{if .Name}} COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}} {{.Name}}:{{range .VisibleCommands}}

Loading…
Cancel
Save