@@ -79,6 +79,10 @@ GLOBAL OPTIONS:{{template "visiblePersistentFlagTemplate" .}}{{end}}
7979 uses text/template to render templates. You can render custom help text by
8080 setting this variable.
8181
82+ var DefaultAppComplete = DefaultRootCommandComplete
83+ DefaultAppComplete is a backward-compatible name for
84+ DefaultRootCommandComplete.
85+
8286var DefaultInverseBoolPrefix = "no-"
8387var ErrWriter io.Writer = os.Stderr
8488 ErrWriter is used to write errors to the user. This can be anything
@@ -131,13 +135,19 @@ COPYRIGHT:
131135 cli.go uses text/template to render templates. You can render custom help
132136 text by setting this variable.
133137
134- var ShowAppHelp = showAppHelp
135- ShowAppHelp is an action that displays the help
138+ var ShowAppHelp = ShowRootCommandHelp
139+ ShowAppHelp is a backward-compatible name for ShowRootCommandHelp.
140+
141+ var ShowAppHelpAndExit = ShowRootCommandHelpAndExit
142+ ShowAppHelpAndExit is a backward-compatible name for ShowRootCommandHelp.
136143
137- var ShowCommandHelp = showCommandHelp
144+ var ShowCommandHelp = DefaultShowCommandHelp
138145 ShowCommandHelp prints help for the given command
139146
140- var ShowSubcommandHelp = showSubcommandHelp
147+ var ShowRootCommandHelp = DefaultShowRootCommandHelp
148+ ShowRootCommandHelp is an action that displays help for the root command.
149+
150+ var ShowSubcommandHelp = DefaultShowSubcommandHelp
141151 ShowSubcommandHelp prints help for the given subcommand
142152
143153var SubcommandHelpTemplate = `NAME:
@@ -162,37 +172,40 @@ OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
162172 cli.go uses text/template to render templates. You can render custom help
163173 text by setting this variable.
164174
165- var VersionPrinter = printVersion
166- VersionPrinter prints the version for the App
175+ var VersionPrinter = DefaultPrintVersion
176+ VersionPrinter prints the version for the root Command.
167177
168- var HelpPrinter helpPrinter = printHelp
169- HelpPrinter is a function that writes the help output. If not set
170- explicitly, this calls HelpPrinterCustom using only the default template
171- functions.
172178
173- If custom logic for printing help is required, this function can be
174- overridden. If the ExtraInfo field is defined on an App, this function
175- should not be modified, as HelpPrinterCustom will be used directly in order
176- to capture the extra information.
179+ FUNCTIONS
177180
178- var HelpPrinterCustom helpPrinterCustom = printHelpCustom
179- HelpPrinterCustom is a function that writes the help output. It is used as
180- the default implementation of HelpPrinter, and may be called directly if the
181- ExtraInfo field is set on an App.
181+ func DefaultCompleteWithFlags(ctx context.Context, cmd *Command)
182+ func DefaultPrintHelp(out io.Writer, templ string, data any)
183+ DefaultPrintHelp is the default implementation of HelpPrinter.
182184
183- In the default implementation, if the customFuncs argument contains a
184- "wrapAt" key, which is a function which takes no arguments and returns an
185- int, this int value will be used to produce a "wrap" function used by the
186- default template to wrap long lines.
185+ func DefaultPrintHelpCustom(out io.Writer, templ string, data any, customFuncs map[string]any)
186+ DefaultPrintHelpCustom is the default implementation of HelpPrinterCustom.
187187
188+ The customFuncs map will be combined with a default template.FuncMap to
189+ allow using arbitrary functions in template rendering.
188190
189- FUNCTIONS
191+ func DefaultPrintVersion(cmd *Command)
192+ DefaultPrintVersion is the default implementation of VersionPrinter.
190193
191- func DefaultAppComplete(ctx context.Context, cmd *Command)
192- DefaultAppComplete prints the list of subcommands as the default app
193- completion method
194+ func DefaultRootCommandComplete(ctx context.Context, cmd *Command)
195+ DefaultRootCommandComplete prints the list of subcommands as the default
196+ completion method.
197+
198+ func DefaultShowCommandHelp(ctx context.Context, cmd *Command, commandName string) error
199+ DefaultShowCommandHelp is the default implementation of ShowCommandHelp.
200+
201+ func DefaultShowRootCommandHelp(cmd *Command) error
202+ DefaultShowRootCommandHelp is the default implementation of
203+ ShowRootCommandHelp.
204+
205+ func DefaultShowSubcommandHelp(cmd *Command) error
206+ DefaultShowSubcommandHelp is the default implementation of
207+ ShowSubcommandHelp.
194208
195- func DefaultCompleteWithFlags(ctx context.Context, cmd *Command)
196209func FlagNames(name string, aliases []string) []string
197210func HandleExitCoder(err error)
198211 HandleExitCoder handles errors implementing ExitCoder by printing their
@@ -202,21 +215,22 @@ func HandleExitCoder(err error)
202215 for the ExitCoder interface, and OsExiter will be called with the last exit
203216 code found, or exit code 1 if no ExitCoder is found.
204217
205- This function is the default error-handling behavior for an App.
206-
207- func ShowAppHelpAndExit(cmd *Command, exitCode int)
208- ShowAppHelpAndExit - Prints the list of subcommands for the app and exits
209- with exit code.
218+ This function is the default error-handling behavior for a Command.
210219
211220func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, code int)
212- ShowCommandHelpAndExit - exits with code after showing help
221+ ShowCommandHelpAndExit exits with code after showing help via
222+ ShowCommandHelp.
223+
224+ func ShowRootCommandHelpAndExit(cmd *Command, exitCode int)
225+ ShowRootCommandHelpAndExit prints the list of subcommands and exits with
226+ exit code.
213227
214228func ShowSubcommandHelpAndExit(cmd *Command, exitCode int)
215- ShowSubcommandHelpAndExit - Prints help for the given subcommand and exits
216- with exit code.
229+ ShowSubcommandHelpAndExit prints help for the given subcommand via
230+ ShowSubcommandHelp and exits with exit code.
217231
218232func ShowVersion(cmd *Command)
219- ShowVersion prints the version number of the App
233+ ShowVersion prints the version number of the root Command.
220234
221235
222236TYPES
@@ -472,9 +486,9 @@ type Command struct {
472486 Writer io.Writer `json:"-"`
473487 // ErrWriter writes error output
474488 ErrWriter io.Writer `json:"-"`
475- // ExitErrHandler processes any error encountered while running an App before
476- // it is returned to the caller. If no function is provided, HandleExitCoder
477- // is used as the default behavior.
489+ // ExitErrHandler processes any error encountered while running a Command before it is
490+ // returned to the caller. If no function is provided, HandleExitCoder is used as the
491+ // default behavior.
478492 ExitErrHandler ExitErrHandlerFunc `json:"-"`
479493 // Other custom info
480494 Metadata map[string]interface{} `json:"metadata"`
@@ -687,7 +701,7 @@ func (c *Command) TimestampArg(name string) time.Time
687701func (c *Command) TimestampArgs(name string) []time.Time
688702
689703func (cmd *Command) ToFishCompletion() (string, error)
690- ToFishCompletion creates a fish completion string for the `*App ` The
704+ ToFishCompletion creates a fish completion string for the `*Command ` The
691705 function errors if either parsing or writing of the string fails.
692706
693707func (cmd *Command) Uint(name string) uint
@@ -847,16 +861,15 @@ type ExitCoder interface {
847861 error
848862 ExitCode() int
849863}
850- ExitCoder is the interface checked by `App` and `Command` for a custom exit
851- code
864+ ExitCoder is the interface checked by `Command` for a custom exit code.
852865
853- func Exit(message interface{} , exitCode int) ExitCoder
866+ func Exit(message any , exitCode int) ExitCoder
854867 Exit wraps a message and exit code into an error, which by default is
855868 handled with a call to os.Exit during default error handling.
856869
857- This is the simplest way to trigger a non-zero exit code for an App
858- without having to call os.Exit manually. During testing, this behavior
859- can be avoided by overriding the ExitErrHandler function on an App or the
870+ This is the simplest way to trigger a non-zero exit code for a Command
871+ without having to call os.Exit manually. During testing, this behavior can
872+ be avoided by overriding the ExitErrHandler function on a Command or the
860873 package-global OsExiter function.
861874
862875type ExitErrHandlerFunc func(context.Context, *Command, error)
@@ -1093,6 +1106,32 @@ type FloatSliceFlag = FlagBase[[]float64, NoConfig, FloatSlice]
10931106
10941107type GenericFlag = FlagBase[Value, NoConfig, genericValue]
10951108
1109+ type HelpPrinterCustomFunc func(w io.Writer, templ string, data any, customFunc map[string]any)
1110+ Prints help for the Command with custom template function.
1111+
1112+ var HelpPrinterCustom HelpPrinterCustomFunc = DefaultPrintHelpCustom
1113+ HelpPrinterCustom is a function that writes the help output. It is used as
1114+ the default implementation of HelpPrinter, and may be called directly if the
1115+ ExtraInfo field is set on a Command.
1116+
1117+ In the default implementation, if the customFuncs argument contains a
1118+ "wrapAt" key, which is a function which takes no arguments and returns an
1119+ int, this int value will be used to produce a "wrap" function used by the
1120+ default template to wrap long lines.
1121+
1122+ type HelpPrinterFunc func(w io.Writer, templ string, data any)
1123+ HelpPrinterFunc prints help for the Command.
1124+
1125+ var HelpPrinter HelpPrinterFunc = DefaultPrintHelp
1126+ HelpPrinter is a function that writes the help output. If not set
1127+ explicitly, this calls HelpPrinterCustom using only the default template
1128+ functions.
1129+
1130+ If custom logic for printing help is required, this function can be
1131+ overridden. If the ExtraInfo field is defined on a Command, this function
1132+ should not be modified, as HelpPrinterCustom will be used directly in order
1133+ to capture the extra information.
1134+
10961135type Int16Arg = ArgumentBase[int16, IntegerConfig, intValue[int16]]
10971136
10981137type Int16Args = ArgumentsBase[int16, IntegerConfig, intValue[int16]]
0 commit comments