Skip to content

Commit

Permalink
Merge pull request #1054 from itchyny/subcommand-consistent-description
Browse files Browse the repository at this point in the history
Fix description of subcommand more consistent
  • Loading branch information
coilysiren authored Jan 29, 2020
2 parents 3f8c3bc + aed5577 commit ffbb8c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,8 @@ func TestApp_Run_CommandSubcommandHelpName(t *testing.T) {
}
cmd := &Command{
Name: "foo",
Description: "foo commands",
Usage: "foo commands",
Description: "This is a description",
Subcommands: []*Command{subCmd},
}
app.Commands = []*Command{cmd}
Expand All @@ -1584,6 +1585,11 @@ func TestApp_Run_CommandSubcommandHelpName(t *testing.T) {
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...]"
if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %q", expected, output)
Expand Down
7 changes: 5 additions & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ OPTIONS:
// cli.go uses text/template to render templates. You can
// render custom help text by setting this variable.
var SubcommandHelpTemplate = `NAME:
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
{{.HelpName}} - {{.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}}
{{.Name}}:{{range .VisibleCommands}}
Expand Down

0 comments on commit ffbb8c0

Please sign in to comment.