From e01afb2e4161d853c9ad769a6433b390861b3f67 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Wed, 24 Aug 2022 21:20:43 -0400 Subject: [PATCH] Make test case more robust --- help.go | 1 - help_test.go | 15 +++++++++++---- template.go | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/help.go b/help.go index 881464551b..14f0ff4c05 100644 --- a/help.go +++ b/help.go @@ -297,7 +297,6 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs funcMap := template.FuncMap{ "join": strings.Join, "subtract": subtract, - "add": add, "indent": indent, "nindent": nindent, "trim": strings.TrimSpace, diff --git a/help_test.go b/help_test.go index c3451d9f6b..9422b4a105 100644 --- a/help_test.go +++ b/help_test.go @@ -907,6 +907,11 @@ App UsageText`, Aliases: []string{"frb1", "frbb2", "frl2"}, Usage: "this is a long help output for the run command, long usage \noutput, long usage output, long usage output, long usage output\noutput, long usage output, long usage output", }, + { + Name: "grobbly", + Aliases: []string{"grb1", "grbb2"}, + Usage: "this is another long help output for the run command, long usage \noutput, long usage output", + }, }, } @@ -915,10 +920,12 @@ App UsageText`, _ = app.Run([]string{"foo"}) - expected := `frobbly, frb1, frbb2, frl2 this is a long help output for the run command, long usage - output, long usage output, long usage output, long usage output - output, long usage output, long usage output` - + expected := "COMMANDS:\n" + + " frobbly, frb1, frbb2, frl2 this is a long help output for the run command, long usage \n" + + " output, long usage output, long usage output, long usage output\n" + + " output, long usage output, long usage output\n" + + " grobbly, grb1, grbb2 this is another long help output for the run command, long usage \n" + + " output, long usage output" if !strings.Contains(output.String(), expected) { t.Errorf("expected output to include usage text; got: %q", output.String()) } diff --git a/template.go b/template.go index dd6955c117..7ed2370994 100644 --- a/template.go +++ b/template.go @@ -22,7 +22,7 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: COMMANDS:{{range .VisibleCategories}}{{if .Name}} {{.Name}}:{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}} - {{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (add (len $s) 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}} + {{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}} GLOBAL OPTIONS:{{range .VisibleFlagCategories}} {{if .Name}}{{.Name}} @@ -77,7 +77,7 @@ DESCRIPTION: COMMANDS:{{range .VisibleCategories}}{{if .Name}} {{.Name}}:{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}} - {{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (add (len $s) 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + {{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} OPTIONS: {{range .VisibleFlags}}{{.}}