3232 SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
3333)
3434var AppHelpTemplate = `NAME:
35- {{$v := offset .Name 6}}{{wrap .Name 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end }}
35+ {{template "helpNameTemplate" . }}
3636
3737USAGE:
3838 {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
@@ -41,52 +41,39 @@ VERSION:
4141 {{.Version}}{{end}}{{end}}{{if .Description}}
4242
4343DESCRIPTION:
44- {{wrap .Description 3}}{{end}}{{if len .Authors}}
44+ {{template "descriptionTemplate" .}}{{end}}
45+ {{- if len .Authors}}
4546
46- AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
47- {{range $index, $author := .Authors}}{{if $index}}
48- {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}}
47+ AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
4948
50- COMMANDS:{{range .VisibleCategories}}{{if .Name}}
51- {{.Name}}:{{range .VisibleCommands}}
52- {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
53- {{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}}
49+ COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
5450
55- GLOBAL OPTIONS:{{range .VisibleFlagCategories}}
56- {{if .Name}}{{.Name}}
57- {{end}}{{range .Flags}}{{.}}
58- {{end}}{{end}}{{else}}{{if .VisibleFlags}}
51+ GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
5952
60- GLOBAL OPTIONS:
61- {{range $index, $option := .VisibleFlags}}{{if $index}}
62- {{end}}{{wrap $option.String 6}}{{end}}{{end}}{{end}}{{if .Copyright}}
53+ GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
6354
6455COPYRIGHT:
65- {{wrap .Copyright 3 }}{{end}}
56+ {{template "copyrightTemplate" . }}{{end}}
6657`
6758 AppHelpTemplate is the text template for the Default help topic. cli.go
6859 uses text/template to render templates. You can render custom help text by
6960 setting this variable.
7061
7162var CommandHelpTemplate = `NAME:
72- {{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end }}
63+ {{template "helpNameTemplate" . }}
7364
7465USAGE:
75- {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end }}{{if .Category}}
66+ {{template "usageTemplate" . }}{{if .Category}}
7667
7768CATEGORY:
7869 {{.Category}}{{end}}{{if .Description}}
7970
8071DESCRIPTION:
81- {{wrap .Description 3 }}{{end}}{{if .VisibleFlagCategories}}
72+ {{template "descriptionTemplate" . }}{{end}}{{if .VisibleFlagCategories}}
8273
83- OPTIONS:{{range .VisibleFlagCategories}}
84- {{if .Name}}{{.Name}}
85- {{end}}{{range .Flags}}{{.}}{{end}}{{end}}{{else}}{{if .VisibleFlags}}
74+ OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
8675
87- OPTIONS:
88- {{range .VisibleFlags}}{{.}}{{end}}{{end}}{{end}}
89- `
76+ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}`
9077 CommandHelpTemplate is the text template for the command help topic. cli.go
9178 uses text/template to render templates. You can render custom help text by
9279 setting this variable.
@@ -145,22 +132,19 @@ var OsExiter = os.Exit
145132 os.Exit.
146133
147134var SubcommandHelpTemplate = `NAME:
148- {{.HelpName}} - {{.Usage }}
135+ {{template "helpNameTemplate" . }}
149136
150137USAGE:
151138 {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
152139
153140DESCRIPTION:
154- {{wrap .Description 3 }}{{end}}
141+ {{template "descriptionTemplate" . }}{{end}}{{if .VisibleCommands }}
155142
156- COMMANDS:{{range .VisibleCategories}}{{if .Name}}
157- {{.Name}}:{{range .VisibleCommands}}
158- {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
159- {{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
143+ COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
160144
161- OPTIONS:
162- {{range .VisibleFlags}}{{.}}{{end}}{{end}}
163- `
145+ OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
146+
147+ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} `
164148 SubcommandHelpTemplate is the text template for the subcommand help topic.
165149 cli.go uses text/template to render templates. You can render custom help
166150 text by setting this variable.
@@ -585,6 +569,9 @@ func (c *Command) Run(ctx *Context) (err error)
585569 Run invokes the command given the context, parses ctx.Args() to generate
586570 command-specific flags
587571
572+ func (c *Command) VisibleCommands() []*Command
573+ VisibleCommands returns a slice of the Commands with Hidden=false
574+
588575func (c *Command) VisibleFlagCategories() []VisibleFlagCategory
589576 VisibleFlagCategories returns a slice containing all the visible flag
590577 categories with the flags they contain
0 commit comments