diff --git a/help_test.go b/help_test.go index 407c269173..b31a23b269 100644 --- a/help_test.go +++ b/help_test.go @@ -511,6 +511,36 @@ func TestShowSubcommandHelp_CommandUsageText(t *testing.T) { } } +func TestShowSubcommandHelp_MultiLine_CommandUsageText(t *testing.T) { + app := &App{ + Commands: []*Command{ + { + Name: "frobbly", + UsageText: `This is a +multi +line +UsageText`, + }, + }, + } + + output := &bytes.Buffer{} + app.Writer = output + + _ = app.Run([]string{"foo", "frobbly", "--help"}) + + expected := `USAGE: + This is a + multi + line + UsageText +` + + if !strings.Contains(output.String(), expected) { + t.Errorf("expected output to include usage text; got: %q", output.String()) + } +} + func TestShowSubcommandHelp_SubcommandUsageText(t *testing.T) { app := &App{ Commands: []*Command{ @@ -535,6 +565,40 @@ func TestShowSubcommandHelp_SubcommandUsageText(t *testing.T) { } } +func TestShowSubcommandHelp_MultiLine_SubcommandUsageText(t *testing.T) { + app := &App{ + Commands: []*Command{ + { + Name: "frobbly", + Subcommands: []*Command{ + { + Name: "bobbly", + UsageText: `This is a +multi +line +UsageText`, + }, + }, + }, + }, + } + + output := &bytes.Buffer{} + app.Writer = output + _ = app.Run([]string{"foo", "frobbly", "bobbly", "--help"}) + + expected := `USAGE: + This is a + multi + line + UsageText +` + + if !strings.Contains(output.String(), expected) { + t.Errorf("expected output to include usage text; got: %q", output.String()) + } +} + func TestShowAppHelp_HiddenCommand(t *testing.T) { app := &App{ Commands: []*Command{ diff --git a/template.go b/template.go index 317cc8817d..2977a2709b 100644 --- a/template.go +++ b/template.go @@ -39,7 +39,7 @@ var CommandHelpTemplate = `NAME: {{.HelpName}} - {{.Usage}} USAGE: - {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} + {{if .UsageText}}{{.UsageText | nindent 3 | trim}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} CATEGORY: {{.Category}}{{end}}{{if .Description}}