| 1 |
package cli // import "github.com/urfave/cli/v3" |
| 2 |
|
| 3 |
Package cli provides a minimal framework for creating and organizing command |
| 4 |
line Go applications. cli is designed to be easy to understand and write, |
| 5 |
the most simple cli application can be written as follows: |
| 6 |
|
| 7 |
func main() { |
| 8 |
(&cli.Command{}).Run(context.Background(), os.Args) |
| 9 |
} |
| 10 |
|
| 11 |
Of course this application does not do much, so let's make this an actual |
| 12 |
application: |
| 13 |
|
| 14 |
func main() { |
| 15 |
cmd := &cli.Command{ |
| 16 |
Name: "greet", |
| 17 |
Usage: "say a greeting", |
| 18 |
Action: func(c *cli.Context) error { |
| 19 |
fmt.Println("Greetings") |
| 20 |
return nil |
| 21 |
}, |
| 22 |
} |
| 23 |
|
| 24 |
cmd.Run(context.Background(), os.Args) |
| 25 |
} |
| 26 |
|
| 27 |
VARIABLES |
| 28 |
|
| 29 |
var ( |
| 30 |
NewFloatSlice = NewSliceBase[float64, NoConfig, floatValue[float64]] |
| 31 |
NewFloat32Slice = NewSliceBase[float32, NoConfig, floatValue[float32]] |
| 32 |
NewFloat64Slice = NewSliceBase[float64, NoConfig, floatValue[float64]] |
| 33 |
) |
| 34 |
var ( |
| 35 |
NewIntSlice = NewSliceBase[int, IntegerConfig, intValue[int]] |
| 36 |
NewInt8Slice = NewSliceBase[int8, IntegerConfig, intValue[int8]] |
| 37 |
NewInt16Slice = NewSliceBase[int16, IntegerConfig, intValue[int16]] |
| 38 |
NewInt32Slice = NewSliceBase[int32, IntegerConfig, intValue[int32]] |
| 39 |
NewInt64Slice = NewSliceBase[int64, IntegerConfig, intValue[int64]] |
| 40 |
) |
| 41 |
var ( |
| 42 |
NewUintSlice = NewSliceBase[uint, IntegerConfig, uintValue[uint]] |
| 43 |
NewUint8Slice = NewSliceBase[uint8, IntegerConfig, uintValue[uint8]] |
| 44 |
NewUint16Slice = NewSliceBase[uint16, IntegerConfig, uintValue[uint16]] |
| 45 |
NewUint32Slice = NewSliceBase[uint32, IntegerConfig, uintValue[uint32]] |
| 46 |
NewUint64Slice = NewSliceBase[uint64, IntegerConfig, uintValue[uint64]] |
| 47 |
) |
| 48 |
var ( |
| 49 |
SuggestFlag SuggestFlagFunc = suggestFlag |
| 50 |
SuggestCommand SuggestCommandFunc = suggestCommand |
| 51 |
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate |
| 52 |
) |
| 53 |
var AnyArguments = []Argument{ |
| 54 |
&StringArgs{ |
| 55 |
Max: -1, |
| 56 |
}, |
| 57 |
} |
| 58 |
AnyArguments to differentiate between no arguments(nil) vs aleast one |
| 59 |
|
| 60 |
var ArgsUsageCommandHelp = "[command]" |
| 61 |
ArgsUsageCommandHelp is a short description of the arguments of the help |
| 62 |
command |
| 63 |
|
| 64 |
var CommandHelpTemplate = `NAME: |
| 65 |
{{template "helpNameTemplate" .}} |
| 66 |
|
| 67 |
USAGE: |
| 68 |
{{template "usageTemplate" .}}{{if .Category}} |
| 69 |
|
| 70 |
CATEGORY: |
| 71 |
{{.Category}}{{end}}{{if .Description}} |
| 72 |
|
| 73 |
DESCRIPTION: |
| 74 |
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}} |
| 75 |
|
| 76 |
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} |
| 77 |
|
| 78 |
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .VisiblePersistentFlags}} |
| 79 |
|
| 80 |
GLOBAL OPTIONS:{{template "visiblePersistentFlagTemplate" .}}{{end}} |
| 81 |
` |
| 82 |
CommandHelpTemplate is the text template for the command help topic. cli.go |
| 83 |
uses text/template to render templates. You can render custom help text by |
| 84 |
setting this variable. |
| 85 |
|
| 86 |
var DefaultAppComplete = DefaultRootCommandComplete |
| 87 |
DefaultAppComplete is a backward-compatible name for |
| 88 |
DefaultRootCommandComplete. |
| 89 |
|
| 90 |
var DefaultInverseBoolPrefix = "no-" |
| 91 |
var ErrWriter io.Writer = os.Stderr |
| 92 |
ErrWriter is used to write errors to the user. This can be anything |
| 93 |
implementing the io.Writer interface and defaults to os.Stderr. |
| 94 |
|
| 95 |
var FishCompletionTemplate = `# {{ .Command.Name }} fish shell completion |
| 96 |
|
| 97 |
function __fish_{{ .Command.Name }}_no_subcommand --description 'Test if there has been any subcommand yet' |
| 98 |
for i in (commandline -opc) |
| 99 |
if contains -- $i{{ range $v := .AllCommands }} {{ $v }}{{ end }} |
| 100 |
return 1 |
| 101 |
end |
| 102 |
end |
| 103 |
return 0 |
| 104 |
end |
| 105 |
|
| 106 |
{{ range $v := .Completions }}{{ $v }} |
| 107 |
{{ end }}` |
| 108 |
var NewStringMap = NewMapBase[string, StringConfig, stringValue] |
| 109 |
var NewStringSlice = NewSliceBase[string, StringConfig, stringValue] |
| 110 |
var OsExiter = os.Exit |
| 111 |
OsExiter is the function used when the app exits. If not set defaults to |
| 112 |
os.Exit. |
| 113 |
|
| 114 |
var RootCommandHelpTemplate = `NAME: |
| 115 |
{{template "helpNameTemplate" .}} |
| 116 |
|
| 117 |
USAGE: |
| 118 |
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} |
| 119 |
|
| 120 |
VERSION: |
| 121 |
{{.Version}}{{end}}{{end}}{{if .Description}} |
| 122 |
|
| 123 |
DESCRIPTION: |
| 124 |
{{template "descriptionTemplate" .}}{{end}} |
| 125 |
{{- if len .Authors}} |
| 126 |
|
| 127 |
AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}} |
| 128 |
|
| 129 |
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} |
| 130 |
|
| 131 |
GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} |
| 132 |
|
| 133 |
GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} |
| 134 |
|
| 135 |
COPYRIGHT: |
| 136 |
{{template "copyrightTemplate" .}}{{end}} |
| 137 |
` |
| 138 |
RootCommandHelpTemplate is the text template for the Default help topic. |
| 139 |
cli.go uses text/template to render templates. You can render custom help |
| 140 |
text by setting this variable. |
| 141 |
|
| 142 |
var ShowAppHelp = ShowRootCommandHelp |
| 143 |
ShowAppHelp is a backward-compatible name for ShowRootCommandHelp. |
| 144 |
|
| 145 |
var ShowAppHelpAndExit = ShowRootCommandHelpAndExit |
| 146 |
ShowAppHelpAndExit is a backward-compatible name for ShowRootCommandHelp. |
| 147 |
|
| 148 |
var ShowCommandHelp = DefaultShowCommandHelp |
| 149 |
ShowCommandHelp prints help for the given command |
| 150 |
|
| 151 |
var ShowRootCommandHelp = DefaultShowRootCommandHelp |
| 152 |
ShowRootCommandHelp is an action that displays help for the root command. |
| 153 |
|
| 154 |
var ShowSubcommandHelp = DefaultShowSubcommandHelp |
| 155 |
ShowSubcommandHelp prints help for the given subcommand |
| 156 |
|
| 157 |
var SubcommandHelpTemplate = `NAME: |
| 158 |
{{template "helpNameTemplate" .}} |
| 159 |
|
| 160 |
USAGE: |
| 161 |
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}} |
| 162 |
|
| 163 |
CATEGORY: |
| 164 |
{{.Category}}{{end}}{{if .Description}} |
| 165 |
|
| 166 |
DESCRIPTION: |
| 167 |
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} |
| 168 |
|
| 169 |
COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}} |
| 170 |
|
| 171 |
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} |
| 172 |
|
| 173 |
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .VisiblePersistentFlags}} |
| 174 |
|
| 175 |
GLOBAL OPTIONS:{{template "visiblePersistentFlagTemplate" .}}{{end}} |
| 176 |
` |
| 177 |
SubcommandHelpTemplate is the text template for the subcommand help topic. |
| 178 |
cli.go uses text/template to render templates. You can render custom help |
| 179 |
text by setting this variable. |
| 180 |
|
| 181 |
var UsageCommandHelp = "Shows a list of commands or help for one command" |
| 182 |
UsageCommandHelp is the text to override the USAGE section of the help |
| 183 |
command |
| 184 |
|
| 185 |
var VersionPrinter = DefaultPrintVersion |
| 186 |
VersionPrinter prints the version for the root Command. |
| 187 |
|
| 188 |
|
| 189 |
FUNCTIONS |
| 190 |
|
| 191 |
func DefaultCompleteWithFlags(ctx context.Context, cmd *Command) |
| 192 |
func DefaultPrintHelp(out io.Writer, templ string, data any) |
| 193 |
DefaultPrintHelp is the default implementation of HelpPrinter. |
| 194 |
|
| 195 |
func DefaultPrintHelpCustom(out io.Writer, templ string, data any, customFuncs map[string]any) |
| 196 |
DefaultPrintHelpCustom is the default implementation of HelpPrinterCustom. |
| 197 |
|
| 198 |
The customFuncs map will be combined with a default template.FuncMap to |
| 199 |
allow using arbitrary functions in template rendering. |
| 200 |
|
| 201 |
func DefaultPrintVersion(cmd *Command) |
| 202 |
DefaultPrintVersion is the default implementation of VersionPrinter. |
| 203 |
|
| 204 |
func DefaultRootCommandComplete(ctx context.Context, cmd *Command) |
| 205 |
DefaultRootCommandComplete prints the list of subcommands as the default |
| 206 |
completion method. |
| 207 |
|
| 208 |
func DefaultShowCommandHelp(ctx context.Context, cmd *Command, commandName string) error |
| 209 |
DefaultShowCommandHelp is the default implementation of ShowCommandHelp. |
| 210 |
|
| 211 |
func DefaultShowRootCommandHelp(cmd *Command) error |
| 212 |
DefaultShowRootCommandHelp is the default implementation of |
| 213 |
ShowRootCommandHelp. |
| 214 |
|
| 215 |
func DefaultShowSubcommandHelp(cmd *Command) error |
| 216 |
DefaultShowSubcommandHelp is the default implementation of |
| 217 |
ShowSubcommandHelp. |
| 218 |
|
| 219 |
func FlagNames(name string, aliases []string) []string |
| 220 |
func HandleExitCoder(err error) |
| 221 |
HandleExitCoder handles errors implementing ExitCoder by printing their |
| 222 |
message and calling OsExiter with the given exit code. |
| 223 |
|
| 224 |
If the given error instead implements MultiError, each error will be checked |
| 225 |
for the ExitCoder interface, and OsExiter will be called with the last exit |
| 226 |
code found, or exit code 1 if no ExitCoder is found. |
| 227 |
|
| 228 |
This function is the default error-handling behavior for a Command. |
| 229 |
|
| 230 |
func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, code int) |
| 231 |
ShowCommandHelpAndExit exits with code after showing help via |
| 232 |
ShowCommandHelp. |
| 233 |
|
| 234 |
func ShowRootCommandHelpAndExit(cmd *Command, exitCode int) |
| 235 |
ShowRootCommandHelpAndExit prints the list of subcommands and exits with |
| 236 |
exit code. |
| 237 |
|
| 238 |
func ShowSubcommandHelpAndExit(cmd *Command, exitCode int) |
| 239 |
ShowSubcommandHelpAndExit prints help for the given subcommand via |
| 240 |
ShowSubcommandHelp and exits with exit code. |
| 241 |
|
| 242 |
func ShowVersion(cmd *Command) |
| 243 |
ShowVersion prints the version number of the root Command. |
| 244 |
|
| 245 |
|
| 246 |
TYPES |
| 247 |
|
| 248 |
type ActionFunc func(context.Context, *Command) error |
| 249 |
ActionFunc is the action to execute when no subcommands are specified |
| 250 |
|
| 251 |
type ActionableFlag interface { |
| 252 |
RunAction(context.Context, *Command) error |
| 253 |
} |
| 254 |
ActionableFlag is an interface that wraps Flag interface and RunAction |
| 255 |
operation. |
| 256 |
|
| 257 |
type AfterFunc func(context.Context, *Command) error |
| 258 |
AfterFunc is an action that executes after any subcommands are run and have |
| 259 |
finished. The AfterFunc is run even if Action() panics. |
| 260 |
|
| 261 |
type Args interface { |
| 262 |
// Get returns the nth argument, or else a blank string |
| 263 |
Get(n int) string |
| 264 |
// First returns the first argument, or else a blank string |
| 265 |
First() string |
| 266 |
// Tail returns the rest of the arguments (not the first one) |
| 267 |
// or else an empty string slice |
| 268 |
Tail() []string |
| 269 |
// Len returns the length of the wrapped slice |
| 270 |
Len() int |
| 271 |
// Present checks if there are any arguments present |
| 272 |
Present() bool |
| 273 |
// Slice returns a copy of the internal slice |
| 274 |
Slice() []string |
| 275 |
} |
| 276 |
|
| 277 |
type Argument interface { |
| 278 |
// which this argument can be accessed using the given name |
| 279 |
HasName(string) bool |
| 280 |
|
| 281 |
// Parse the given args and return unparsed args and/or error |
| 282 |
Parse([]string) ([]string, error) |
| 283 |
|
| 284 |
// The usage template for this argument to use in help |
| 285 |
Usage() string |
| 286 |
|
| 287 |
// The Value of this Arg |
| 288 |
Get() any |
| 289 |
} |
| 290 |
Argument captures a positional argument that can be parsed |
| 291 |
|
| 292 |
type ArgumentBase[T any, C any, VC ValueCreator[T, C]] struct { |
| 293 |
Name string `json:"name"` // the name of this argument |
| 294 |
Value T `json:"value"` // the default value of this argument |
| 295 |
Destination *T `json:"-"` // the destination point for this argument |
| 296 |
UsageText string `json:"usageText"` // the usage text to show |
| 297 |
Config C `json:"config"` // config for this argument similar to Flag Config |
| 298 |
|
| 299 |
// Has unexported fields. |
| 300 |
} |
| 301 |
|
| 302 |
func (a *ArgumentBase[T, C, VC]) Get() any |
| 303 |
|
| 304 |
func (a *ArgumentBase[T, C, VC]) HasName(s string) bool |
| 305 |
|
| 306 |
func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) |
| 307 |
|
| 308 |
func (a *ArgumentBase[T, C, VC]) Usage() string |
| 309 |
|
| 310 |
type ArgumentsBase[T any, C any, VC ValueCreator[T, C]] struct { |
| 311 |
Name string `json:"name"` // the name of this argument |
| 312 |
Value T `json:"value"` // the default value of this argument |
| 313 |
Destination *[]T `json:"-"` // the destination point for this argument |
| 314 |
UsageText string `json:"usageText"` // the usage text to show |
| 315 |
Min int `json:"minTimes"` // the min num of occurrences of this argument |
| 316 |
Max int `json:"maxTimes"` // the max num of occurrences of this argument, set to -1 for unlimited |
| 317 |
Config C `json:"config"` // config for this argument similar to Flag Config |
| 318 |
|
| 319 |
// Has unexported fields. |
| 320 |
} |
| 321 |
ArgumentsBase is a base type for slice arguments |
| 322 |
|
| 323 |
func (a *ArgumentsBase[T, C, VC]) Get() any |
| 324 |
|
| 325 |
func (a *ArgumentsBase[T, C, VC]) HasName(s string) bool |
| 326 |
|
| 327 |
func (a *ArgumentsBase[T, C, VC]) Parse(s []string) ([]string, error) |
| 328 |
|
| 329 |
func (a *ArgumentsBase[T, C, VC]) Usage() string |
| 330 |
|
| 331 |
type BeforeFunc func(context.Context, *Command) (context.Context, error) |
| 332 |
BeforeFunc is an action that executes prior to any subcommands being run |
| 333 |
once the context is ready. If a non-nil error is returned, no subcommands |
| 334 |
are run. |
| 335 |
|
| 336 |
type BoolConfig struct { |
| 337 |
Count *int |
| 338 |
} |
| 339 |
BoolConfig defines the configuration for bool flags |
| 340 |
|
| 341 |
type BoolFlag = FlagBase[bool, BoolConfig, boolValue] |
| 342 |
|
| 343 |
type BoolWithInverseFlag struct { |
| 344 |
Name string `json:"name"` // name of the flag |
| 345 |
Category string `json:"category"` // category of the flag, if any |
| 346 |
DefaultText string `json:"defaultText"` // default text of the flag for usage purposes |
| 347 |
HideDefault bool `json:"hideDefault"` // whether to hide the default value in output |
| 348 |
Usage string `json:"usage"` // usage string for help output |
| 349 |
Sources ValueSourceChain `json:"-"` // sources to load flag value from |
| 350 |
Required bool `json:"required"` // whether the flag is required or not |
| 351 |
Hidden bool `json:"hidden"` // whether to hide the flag in help output |
| 352 |
Local bool `json:"local"` // whether the flag needs to be applied to subcommands as well |
| 353 |
Value bool `json:"defaultValue"` // default value for this flag if not set by from any source |
| 354 |
Destination *bool `json:"-"` // destination pointer for value when set |
| 355 |
Aliases []string `json:"aliases"` // Aliases that are allowed for this flag |
| 356 |
TakesFile bool `json:"takesFileArg"` // whether this flag takes a file argument, mainly for shell completion purposes |
| 357 |
Action func(context.Context, *Command, bool) error `json:"-"` // Action callback to be called when flag is set |
| 358 |
OnlyOnce bool `json:"onlyOnce"` // whether this flag can be duplicated on the command line |
| 359 |
Validator func(bool) error `json:"-"` // custom function to validate this flag value |
| 360 |
ValidateDefaults bool `json:"validateDefaults"` // whether to validate defaults or not |
| 361 |
Config BoolConfig `json:"config"` // Additional/Custom configuration associated with this flag type |
| 362 |
InversePrefix string `json:"invPrefix"` // The prefix used to indicate a negative value. Default: `env` becomes `no-env` |
| 363 |
|
| 364 |
// Has unexported fields. |
| 365 |
} |
| 366 |
|
| 367 |
func (bif *BoolWithInverseFlag) Count() int |
| 368 |
Count returns the number of times this flag has been invoked |
| 369 |
|
| 370 |
func (bif *BoolWithInverseFlag) Get() any |
| 371 |
|
| 372 |
func (bif *BoolWithInverseFlag) GetCategory() string |
| 373 |
GetCategory returns the category of the flag |
| 374 |
|
| 375 |
func (bif *BoolWithInverseFlag) GetDefaultText() string |
| 376 |
GetDefaultText returns the default text for this flag |
| 377 |
|
| 378 |
func (bif *BoolWithInverseFlag) GetEnvVars() []string |
| 379 |
GetEnvVars returns the env vars for this flag |
| 380 |
|
| 381 |
func (bif *BoolWithInverseFlag) GetUsage() string |
| 382 |
GetUsage returns the usage string for the flag |
| 383 |
|
| 384 |
func (bif *BoolWithInverseFlag) GetValue() string |
| 385 |
GetValue returns the flags value as string representation and an empty |
| 386 |
string if the flag takes no value at all. |
| 387 |
|
| 388 |
func (bif *BoolWithInverseFlag) IsBoolFlag() bool |
| 389 |
IsBoolFlag returns whether the flag doesn't need to accept args |
| 390 |
|
| 391 |
func (bif *BoolWithInverseFlag) IsDefaultVisible() bool |
| 392 |
IsDefaultVisible returns true if the flag is not hidden, otherwise false |
| 393 |
|
| 394 |
func (bif *BoolWithInverseFlag) IsLocal() bool |
| 395 |
|
| 396 |
func (bif *BoolWithInverseFlag) IsRequired() bool |
| 397 |
|
| 398 |
func (bif *BoolWithInverseFlag) IsSet() bool |
| 399 |
|
| 400 |
func (bif *BoolWithInverseFlag) IsVisible() bool |
| 401 |
|
| 402 |
func (bif *BoolWithInverseFlag) Names() []string |
| 403 |
|
| 404 |
func (bif *BoolWithInverseFlag) PostParse() error |
| 405 |
|
| 406 |
func (bif *BoolWithInverseFlag) PreParse() error |
| 407 |
|
| 408 |
func (bif *BoolWithInverseFlag) RunAction(ctx context.Context, cmd *Command) error |
| 409 |
|
| 410 |
func (bif *BoolWithInverseFlag) SchemaItemsType() string |
| 411 |
|
| 412 |
func (bif *BoolWithInverseFlag) SchemaType() string |
| 413 |
|
| 414 |
func (bif *BoolWithInverseFlag) Set(name, val string) error |
| 415 |
|
| 416 |
func (bif *BoolWithInverseFlag) SetCategory(c string) |
| 417 |
|
| 418 |
func (bif *BoolWithInverseFlag) String() string |
| 419 |
String implements the standard Stringer interface. |
| 420 |
|
| 421 |
Example for BoolFlag{Name: "env"} --[no-]env (default: false) |
| 422 |
|
| 423 |
Example for BoolFlag{Name: "env", Aliases: []string{"e"}} --[no-]env, |
| 424 |
-e (default: false) |
| 425 |
|
| 426 |
func (bif *BoolWithInverseFlag) TakesValue() bool |
| 427 |
|
| 428 |
func (bif *BoolWithInverseFlag) TypeName() string |
| 429 |
TypeName is used for stringify/docs. For bool its a no-op |
| 430 |
|
| 431 |
type CategorizableFlag interface { |
| 432 |
// Returns the category of the flag |
| 433 |
GetCategory() string |
| 434 |
|
| 435 |
// Sets the category of the flag |
| 436 |
SetCategory(string) |
| 437 |
} |
| 438 |
CategorizableFlag is an interface that allows us to potentially use a flag |
| 439 |
in a categorized representation. |
| 440 |
|
| 441 |
type Command struct { |
| 442 |
// The name of the command |
| 443 |
Name string `json:"name"` |
| 444 |
// A list of aliases for the command |
| 445 |
Aliases []string `json:"aliases"` |
| 446 |
// A short description of the usage of this command |
| 447 |
Usage string `json:"usage"` |
| 448 |
// Text to override the USAGE section of help |
| 449 |
UsageText string `json:"usageText"` |
| 450 |
// A short description of the arguments of this command |
| 451 |
ArgsUsage string `json:"argsUsage"` |
| 452 |
// Version of the command |
| 453 |
Version string `json:"version"` |
| 454 |
// Longer explanation of how the command works |
| 455 |
Description string `json:"description"` |
| 456 |
// DefaultCommand is the (optional) name of a command |
| 457 |
// to run if no command names are passed as CLI arguments. |
| 458 |
DefaultCommand string `json:"defaultCommand"` |
| 459 |
// The category the command is part of |
| 460 |
Category string `json:"category"` |
| 461 |
// List of child commands |
| 462 |
Commands []*Command `json:"commands"` |
| 463 |
// List of flags to parse |
| 464 |
Flags []Flag `json:"flags"` |
| 465 |
// Boolean to hide built-in help command and help flag |
| 466 |
HideHelp bool `json:"hideHelp"` |
| 467 |
// Ignored if HideHelp is true. |
| 468 |
HideHelpCommand bool `json:"hideHelpCommand"` |
| 469 |
// Boolean to hide built-in version flag and the VERSION section of help |
| 470 |
HideVersion bool `json:"hideVersion"` |
| 471 |
// Boolean to enable shell completion commands |
| 472 |
EnableShellCompletion bool `json:"-"` |
| 473 |
// Shell Completion generation command name |
| 474 |
ShellCompletionCommandName string `json:"-"` |
| 475 |
// The function to call when checking for shell command completions |
| 476 |
ShellComplete ShellCompleteFunc `json:"-"` |
| 477 |
// The function to configure a shell completion command |
| 478 |
ConfigureShellCompletionCommand ConfigureShellCompletionCommand `json:"-"` |
| 479 |
// An action to execute before any subcommands are run, but after the context is ready |
| 480 |
// If a non-nil error is returned, no subcommands are run |
| 481 |
Before BeforeFunc `json:"-"` |
| 482 |
// An action to execute after any subcommands are run, but after the subcommand has finished |
| 483 |
// It is run even if Action() panics |
| 484 |
After AfterFunc `json:"-"` |
| 485 |
// The function to call when this command is invoked |
| 486 |
Action ActionFunc `json:"-"` |
| 487 |
// Execute this function if the proper command cannot be found |
| 488 |
CommandNotFound CommandNotFoundFunc `json:"-"` |
| 489 |
// Execute this function if a usage error occurs. |
| 490 |
OnUsageError OnUsageErrorFunc `json:"-"` |
| 491 |
// Execute this function when an invalid flag is accessed from the context |
| 492 |
InvalidFlagAccessHandler InvalidFlagAccessFunc `json:"-"` |
| 493 |
// Boolean to hide this command from help or completion |
| 494 |
Hidden bool `json:"hidden"` |
| 495 |
// List of all authors who contributed (string or fmt.Stringer) |
| 496 |
// TODO: ~string | fmt.Stringer when interface unions are available |
| 497 |
Authors []any `json:"authors"` |
| 498 |
// Copyright of the binary if any |
| 499 |
Copyright string `json:"copyright"` |
| 500 |
// Reader reader to write input to (useful for tests) |
| 501 |
Reader io.Reader `json:"-"` |
| 502 |
// Writer writer to write output to |
| 503 |
Writer io.Writer `json:"-"` |
| 504 |
// ErrWriter writes error output |
| 505 |
ErrWriter io.Writer `json:"-"` |
| 506 |
// ExitErrHandler processes any error encountered while running a Command before it is |
| 507 |
// returned to the caller. If no function is provided, HandleExitCoder is used as the |
| 508 |
// default behavior. |
| 509 |
ExitErrHandler ExitErrHandlerFunc `json:"-"` |
| 510 |
// Other custom info |
| 511 |
Metadata map[string]any `json:"metadata"` |
| 512 |
// Carries a function which returns app specific info. |
| 513 |
ExtraInfo func() map[string]string `json:"-"` |
| 514 |
// CustomRootCommandHelpTemplate the text template for app help topic. |
| 515 |
// cli.go uses text/template to render templates. You can |
| 516 |
// render custom help text by setting this variable. |
| 517 |
CustomRootCommandHelpTemplate string `json:"-"` |
| 518 |
// SliceFlagSeparator is used to customize the separator for SliceFlag, the default is "," |
| 519 |
SliceFlagSeparator string `json:"sliceFlagSeparator"` |
| 520 |
// DisableSliceFlagSeparator is used to disable SliceFlagSeparator, the default is false |
| 521 |
DisableSliceFlagSeparator bool `json:"disableSliceFlagSeparator"` |
| 522 |
// MapFlagKeyValueSeparator is used to customize the separator for MapFlag, the default is "=" |
| 523 |
MapFlagKeyValueSeparator string `json:"mapFlagKeyValueSeparator"` |
| 524 |
// Boolean to enable short-option handling so user can combine several |
| 525 |
// single-character bool arguments into one |
| 526 |
// i.e. foobar -o -v -> foobar -ov |
| 527 |
UseShortOptionHandling bool `json:"useShortOptionHandling"` |
| 528 |
// Enable suggestions for commands and flags |
| 529 |
Suggest bool `json:"suggest"` |
| 530 |
// Allows global flags set by libraries which use flag.XXXVar(...) directly |
| 531 |
// to be parsed through this library |
| 532 |
AllowExtFlags bool `json:"allowExtFlags"` |
| 533 |
// Treat all flags as normal arguments if true |
| 534 |
SkipFlagParsing bool `json:"skipFlagParsing"` |
| 535 |
// CustomHelpTemplate the text template for the command help topic. |
| 536 |
// cli.go uses text/template to render templates. You can |
| 537 |
// render custom help text by setting this variable. |
| 538 |
CustomHelpTemplate string `json:"-"` |
| 539 |
// Use longest prefix match for commands |
| 540 |
PrefixMatchCommands bool `json:"prefixMatchCommands"` |
| 541 |
// Custom suggest command for matching |
| 542 |
SuggestCommandFunc SuggestCommandFunc `json:"-"` |
| 543 |
// Flag exclusion group |
| 544 |
MutuallyExclusiveFlags []MutuallyExclusiveFlags `json:"mutuallyExclusiveFlags"` |
| 545 |
// Arguments to parse for this command |
| 546 |
Arguments []Argument `json:"arguments"` |
| 547 |
// Whether to read arguments from stdin |
| 548 |
// applicable to root command only |
| 549 |
ReadArgsFromStdin bool `json:"readArgsFromStdin"` |
| 550 |
// StopOnNthArg provides v2-like behavior for specific commands by stopping |
| 551 |
// flag parsing after N positional arguments are encountered. When set to N, |
| 552 |
// all remaining arguments after the Nth positional argument will be treated |
| 553 |
// as arguments, not flags. |
| 554 |
// |
| 555 |
// A value of 0 means all arguments are treated as positional (no flag parsing). |
| 556 |
// A nil value means normal v3 flag parsing behavior (flags can appear anywhere). |
| 557 |
StopOnNthArg *int `json:"stopOnNthArg"` |
| 558 |
|
| 559 |
// Has unexported fields. |
| 560 |
} |
| 561 |
Command contains everything needed to run an application that accepts a |
| 562 |
string slice of arguments such as os.Args. A given Command may contain Flags |
| 563 |
and sub-commands in Commands. |
| 564 |
|
| 565 |
func (cmd *Command) Args() Args |
| 566 |
Args returns the command line arguments associated with the command. |
| 567 |
|
| 568 |
func (cmd *Command) Bool(name string) bool |
| 569 |
|
| 570 |
func (cmd *Command) Command(name string) *Command |
| 571 |
|
| 572 |
func (cmd *Command) Count(name string) int |
| 573 |
Count returns the num of occurrences of this flag |
| 574 |
|
| 575 |
func (cmd *Command) Duration(name string) time.Duration |
| 576 |
|
| 577 |
func (cmd *Command) FlagNames() []string |
| 578 |
FlagNames returns a slice of flag names used by the this command and all of |
| 579 |
its parent commands. |
| 580 |
|
| 581 |
func (cmd *Command) Float(name string) float64 |
| 582 |
Float looks up the value of a local FloatFlag, returns 0 if not found |
| 583 |
|
| 584 |
func (cmd *Command) Float32(name string) float32 |
| 585 |
Float32 looks up the value of a local Float32Flag, returns 0 if not found |
| 586 |
|
| 587 |
func (c *Command) Float32Arg(name string) float32 |
| 588 |
|
| 589 |
func (c *Command) Float32Args(name string) []float32 |
| 590 |
|
| 591 |
func (cmd *Command) Float32Slice(name string) []float32 |
| 592 |
Float32Slice looks up the value of a local Float32Slice, returns nil if not |
| 593 |
found |
| 594 |
|
| 595 |
func (cmd *Command) Float64(name string) float64 |
| 596 |
Float64 looks up the value of a local Float64Flag, returns 0 if not found |
| 597 |
|
| 598 |
func (c *Command) Float64Arg(name string) float64 |
| 599 |
|
| 600 |
func (c *Command) Float64Args(name string) []float64 |
| 601 |
|
| 602 |
func (cmd *Command) Float64Slice(name string) []float64 |
| 603 |
Float64Slice looks up the value of a local Float64SliceFlag, returns nil if |
| 604 |
not found |
| 605 |
|
| 606 |
func (c *Command) FloatArg(name string) float64 |
| 607 |
|
| 608 |
func (c *Command) FloatArgs(name string) []float64 |
| 609 |
|
| 610 |
func (cmd *Command) FloatSlice(name string) []float64 |
| 611 |
FloatSlice looks up the value of a local FloatSliceFlag, returns nil if not |
| 612 |
found |
| 613 |
|
| 614 |
func (cmd *Command) FullName() string |
| 615 |
FullName returns the full name of the command. Includes parent commands |
| 616 |
separated by space. |
| 617 |
|
| 618 |
func (cmd *Command) Generic(name string) Value |
| 619 |
Generic looks up the value of a local GenericFlag, returns nil if not found |
| 620 |
|
| 621 |
func (cmd *Command) HasName(name string) bool |
| 622 |
HasName returns true if Command.Name matches given name |
| 623 |
|
| 624 |
func (cmd *Command) Int(name string) int |
| 625 |
Int looks up the value of a local Int64Flag, returns 0 if not found |
| 626 |
|
| 627 |
func (cmd *Command) Int16(name string) int16 |
| 628 |
Int16 looks up the value of a local Int16Flag, returns 0 if not found |
| 629 |
|
| 630 |
func (c *Command) Int16Arg(name string) int16 |
| 631 |
|
| 632 |
func (c *Command) Int16Args(name string) []int16 |
| 633 |
|
| 634 |
func (cmd *Command) Int16Slice(name string) []int16 |
| 635 |
Int16Slice looks up the value of a local Int16SliceFlag, returns nil if not |
| 636 |
found |
| 637 |
|
| 638 |
func (cmd *Command) Int32(name string) int32 |
| 639 |
Int32 looks up the value of a local Int32Flag, returns 0 if not found |
| 640 |
|
| 641 |
func (c *Command) Int32Arg(name string) int32 |
| 642 |
|
| 643 |
func (c *Command) Int32Args(name string) []int32 |
| 644 |
|
| 645 |
func (cmd *Command) Int32Slice(name string) []int32 |
| 646 |
Int32Slice looks up the value of a local Int32SliceFlag, returns nil if not |
| 647 |
found |
| 648 |
|
| 649 |
func (cmd *Command) Int64(name string) int64 |
| 650 |
Int64 looks up the value of a local Int64Flag, returns 0 if not found |
| 651 |
|
| 652 |
func (c *Command) Int64Arg(name string) int64 |
| 653 |
|
| 654 |
func (c *Command) Int64Args(name string) []int64 |
| 655 |
|
| 656 |
func (cmd *Command) Int64Slice(name string) []int64 |
| 657 |
Int64Slice looks up the value of a local Int64SliceFlag, returns nil if not |
| 658 |
found |
| 659 |
|
| 660 |
func (cmd *Command) Int8(name string) int8 |
| 661 |
Int8 looks up the value of a local Int8Flag, returns 0 if not found |
| 662 |
|
| 663 |
func (c *Command) Int8Arg(name string) int8 |
| 664 |
|
| 665 |
func (c *Command) Int8Args(name string) []int8 |
| 666 |
|
| 667 |
func (cmd *Command) Int8Slice(name string) []int8 |
| 668 |
Int8Slice looks up the value of a local Int8SliceFlag, returns nil if not |
| 669 |
found |
| 670 |
|
| 671 |
func (c *Command) IntArg(name string) int |
| 672 |
|
| 673 |
func (c *Command) IntArgs(name string) []int |
| 674 |
|
| 675 |
func (cmd *Command) IntSlice(name string) []int |
| 676 |
IntSlice looks up the value of a local IntSliceFlag, returns nil if not |
| 677 |
found |
| 678 |
|
| 679 |
func (cmd *Command) IsSet(name string) bool |
| 680 |
IsSet determines if the flag was actually set |
| 681 |
|
| 682 |
func (cmd *Command) Lineage() []*Command |
| 683 |
Lineage returns *this* command and all of its ancestor commands in order |
| 684 |
from child to parent |
| 685 |
|
| 686 |
func (cmd *Command) LocalFlagNames() []string |
| 687 |
LocalFlagNames returns a slice of flag names used in this command. |
| 688 |
|
| 689 |
func (cmd *Command) NArg() int |
| 690 |
NArg returns the number of the command line arguments. |
| 691 |
|
| 692 |
func (cmd *Command) Names() []string |
| 693 |
Names returns the names including short names and aliases. |
| 694 |
|
| 695 |
func (cmd *Command) NumFlags() int |
| 696 |
NumFlags returns the number of flags set |
| 697 |
|
| 698 |
func (cmd *Command) Path() []string |
| 699 |
Path returns the path of command names from the root to cmd, inclusive. |
| 700 |
Each element is a Command.Name. Path traverses upward via parent pointers |
| 701 |
similar to Lineage. FullName() is equivalent to strings.Join(cmd.Path(), |
| 702 |
" "). |
| 703 |
|
| 704 |
func (cmd *Command) Root() *Command |
| 705 |
Root returns the Command at the root of the graph |
| 706 |
|
| 707 |
func (cmd *Command) Run(ctx context.Context, osArgs []string) (deferErr error) |
| 708 |
Run is the entry point to the command graph. The positional arguments are |
| 709 |
parsed according to the Flag and Command definitions and the matching Action |
| 710 |
functions are run. |
| 711 |
|
| 712 |
func (cmd *Command) Set(name, value string) error |
| 713 |
Set sets a context flag to a value. |
| 714 |
|
| 715 |
func (cmd *Command) String(name string) string |
| 716 |
|
| 717 |
func (c *Command) StringArg(name string) string |
| 718 |
|
| 719 |
func (c *Command) StringArgs(name string) []string |
| 720 |
|
| 721 |
func (cmd *Command) StringMap(name string) map[string]string |
| 722 |
StringMap looks up the value of a local StringMapFlag, returns nil if not |
| 723 |
found |
| 724 |
|
| 725 |
func (cmd *Command) StringSlice(name string) []string |
| 726 |
StringSlice looks up the value of a local StringSliceFlag, returns nil if |
| 727 |
not found |
| 728 |
|
| 729 |
func (cmd *Command) Timestamp(name string) time.Time |
| 730 |
Timestamp gets the timestamp from a flag name |
| 731 |
|
| 732 |
func (c *Command) TimestampArg(name string) time.Time |
| 733 |
|
| 734 |
func (c *Command) TimestampArgs(name string) []time.Time |
| 735 |
|
| 736 |
func (cmd *Command) ToFishCompletion() (string, error) |
| 737 |
ToFishCompletion creates a fish completion string for the `*Command` The |
| 738 |
function errors if either parsing or writing of the string fails. |
| 739 |
|
| 740 |
func (cmd *Command) Uint(name string) uint |
| 741 |
Uint looks up the value of a local Uint64Flag, returns 0 if not found |
| 742 |
|
| 743 |
func (cmd *Command) Uint16(name string) uint16 |
| 744 |
Uint16 looks up the value of a local Uint16Flag, returns 0 if not found |
| 745 |
|
| 746 |
func (c *Command) Uint16Arg(name string) uint16 |
| 747 |
|
| 748 |
func (c *Command) Uint16Args(name string) []uint16 |
| 749 |
|
| 750 |
func (cmd *Command) Uint16Slice(name string) []uint16 |
| 751 |
Uint16Slice looks up the value of a local Uint16SliceFlag, returns nil if |
| 752 |
not found |
| 753 |
|
| 754 |
func (cmd *Command) Uint32(name string) uint32 |
| 755 |
Uint32 looks up the value of a local Uint32Flag, returns 0 if not found |
| 756 |
|
| 757 |
func (c *Command) Uint32Arg(name string) uint32 |
| 758 |
|
| 759 |
func (c *Command) Uint32Args(name string) []uint32 |
| 760 |
|
| 761 |
func (cmd *Command) Uint32Slice(name string) []uint32 |
| 762 |
Uint32Slice looks up the value of a local Uint32SliceFlag, returns nil if |
| 763 |
not found |
| 764 |
|
| 765 |
func (cmd *Command) Uint64(name string) uint64 |
| 766 |
Uint64 looks up the value of a local Uint64Flag, returns 0 if not found |
| 767 |
|
| 768 |
func (c *Command) Uint64Arg(name string) uint64 |
| 769 |
|
| 770 |
func (c *Command) Uint64Args(name string) []uint64 |
| 771 |
|
| 772 |
func (cmd *Command) Uint64Slice(name string) []uint64 |
| 773 |
Uint64Slice looks up the value of a local Uint64SliceFlag, returns nil if |
| 774 |
not found |
| 775 |
|
| 776 |
func (cmd *Command) Uint8(name string) uint8 |
| 777 |
Uint8 looks up the value of a local Uint8Flag, returns 0 if not found |
| 778 |
|
| 779 |
func (c *Command) Uint8Arg(name string) uint8 |
| 780 |
|
| 781 |
func (c *Command) Uint8Args(name string) []uint8 |
| 782 |
|
| 783 |
func (cmd *Command) Uint8Slice(name string) []uint8 |
| 784 |
Uint8Slice looks up the value of a local Uint8SliceFlag, returns nil if not |
| 785 |
found |
| 786 |
|
| 787 |
func (c *Command) UintArg(name string) uint |
| 788 |
|
| 789 |
func (c *Command) UintArgs(name string) []uint |
| 790 |
|
| 791 |
func (cmd *Command) UintSlice(name string) []uint |
| 792 |
UintSlice looks up the value of a local UintSliceFlag, returns nil if not |
| 793 |
found |
| 794 |
|
| 795 |
func (cmd *Command) Value(name string) any |
| 796 |
Value returns the value of the flag corresponding to `name` |
| 797 |
|
| 798 |
func (cmd *Command) VisibleCategories() []CommandCategory |
| 799 |
VisibleCategories returns a slice of categories and commands that are |
| 800 |
Hidden=false |
| 801 |
|
| 802 |
func (cmd *Command) VisibleCommands() []*Command |
| 803 |
VisibleCommands returns a slice of the Commands with Hidden=false |
| 804 |
|
| 805 |
func (cmd *Command) VisibleFlagCategories() []VisibleFlagCategory |
| 806 |
VisibleFlagCategories returns a slice containing all the visible flag |
| 807 |
categories with the flags they contain |
| 808 |
|
| 809 |
func (cmd *Command) VisibleFlags() []Flag |
| 810 |
VisibleFlags returns a slice of the Flags with Hidden=false |
| 811 |
|
| 812 |
func (cmd *Command) VisiblePersistentFlags() []Flag |
| 813 |
VisiblePersistentFlags returns a slice of LocalFlag with Persistent=true and |
| 814 |
Hidden=false. |
| 815 |
|
| 816 |
func (cmd *Command) Walk(fn func(*Command) error) error |
| 817 |
Walk visits cmd and every descendant. If fn returns a non-nil error, |
| 818 |
the walk terminates and the error is returned to the caller. |
| 819 |
|
| 820 |
type CommandCategories interface { |
| 821 |
// AddCommand adds a command to a category, creating a new category if necessary. |
| 822 |
AddCommand(category string, command *Command) |
| 823 |
// Categories returns a slice of categories sorted by name |
| 824 |
Categories() []CommandCategory |
| 825 |
} |
| 826 |
CommandCategories interface allows for category manipulation |
| 827 |
|
| 828 |
type CommandCategory interface { |
| 829 |
// Name returns the category name string |
| 830 |
Name() string |
| 831 |
// VisibleCommands returns a slice of the Commands with Hidden=false |
| 832 |
VisibleCommands() []*Command |
| 833 |
} |
| 834 |
CommandCategory is a category containing commands. |
| 835 |
|
| 836 |
type CommandNotFoundFunc func(context.Context, *Command, string) |
| 837 |
CommandNotFoundFunc is executed if the proper command cannot be found |
| 838 |
|
| 839 |
type ConfigureShellCompletionCommand func(*Command) |
| 840 |
ConfigureShellCompletionCommand is a function to configure a shell |
| 841 |
completion command |
| 842 |
|
| 843 |
type Countable interface { |
| 844 |
Count() int |
| 845 |
} |
| 846 |
Countable is an interface to enable detection of flag values which support |
| 847 |
repetitive flags |
| 848 |
|
| 849 |
type DocGenerationFlag interface { |
| 850 |
// TakesValue returns true if the flag takes a value, otherwise false |
| 851 |
TakesValue() bool |
| 852 |
|
| 853 |
// GetUsage returns the usage string for the flag |
| 854 |
GetUsage() string |
| 855 |
|
| 856 |
// GetValue returns the flags value as string representation and an empty |
| 857 |
// string if the flag takes no value at all. |
| 858 |
GetValue() string |
| 859 |
|
| 860 |
// GetDefaultText returns the default text for this flag |
| 861 |
GetDefaultText() string |
| 862 |
|
| 863 |
// GetEnvVars returns the env vars for this flag |
| 864 |
GetEnvVars() []string |
| 865 |
|
| 866 |
// IsDefaultVisible returns whether the default value should be shown in |
| 867 |
// help text |
| 868 |
IsDefaultVisible() bool |
| 869 |
// TypeName to detect if a flag is a string, bool, etc. |
| 870 |
TypeName() string |
| 871 |
} |
| 872 |
DocGenerationFlag is an interface that allows documentation generation for |
| 873 |
the flag |
| 874 |
|
| 875 |
type DocGenerationMultiValueFlag interface { |
| 876 |
DocGenerationFlag |
| 877 |
|
| 878 |
// IsMultiValueFlag returns true for flags that can be given multiple times. |
| 879 |
IsMultiValueFlag() bool |
| 880 |
} |
| 881 |
DocGenerationMultiValueFlag extends DocGenerationFlag for slice/map based |
| 882 |
flags. |
| 883 |
|
| 884 |
type DurationFlag = FlagBase[time.Duration, NoConfig, durationValue] |
| 885 |
|
| 886 |
type EnvValueSource interface { |
| 887 |
IsFromEnv() bool |
| 888 |
Key() string |
| 889 |
} |
| 890 |
EnvValueSource is to specifically detect env sources when printing help text |
| 891 |
|
| 892 |
type ErrorFormatter interface { |
| 893 |
Format(s fmt.State, verb rune) |
| 894 |
} |
| 895 |
ErrorFormatter is the interface that will suitably format the error output |
| 896 |
|
| 897 |
type ExitCoder interface { |
| 898 |
error |
| 899 |
ExitCode() int |
| 900 |
} |
| 901 |
ExitCoder is the interface checked by `Command` for a custom exit code. |
| 902 |
|
| 903 |
func Exit(message any, exitCode int) ExitCoder |
| 904 |
Exit wraps a message and exit code into an error, which by default is |
| 905 |
handled with a call to os.Exit during default error handling. |
| 906 |
|
| 907 |
This is the simplest way to trigger a non-zero exit code for a Command |
| 908 |
without having to call os.Exit manually. During testing, this behavior can |
| 909 |
be avoided by overriding the ExitErrHandler function on a Command or the |
| 910 |
package-global OsExiter function. |
| 911 |
|
| 912 |
type ExitErrHandlerFunc func(context.Context, *Command, error) |
| 913 |
ExitErrHandlerFunc is executed if provided in order to handle exitError |
| 914 |
values returned by Actions and Before/After functions. |
| 915 |
|
| 916 |
type Flag interface { |
| 917 |
fmt.Stringer |
| 918 |
|
| 919 |
// Retrieve the value of the Flag |
| 920 |
Get() any |
| 921 |
|
| 922 |
// Lifecycle methods. |
| 923 |
// flag callback prior to parsing |
| 924 |
PreParse() error |
| 925 |
|
| 926 |
// flag callback post parsing |
| 927 |
PostParse() error |
| 928 |
|
| 929 |
// Apply Flag settings to the given flag set |
| 930 |
Set(string, string) error |
| 931 |
|
| 932 |
// All possible names for this flag |
| 933 |
Names() []string |
| 934 |
|
| 935 |
// Whether the flag has been set or not |
| 936 |
IsSet() bool |
| 937 |
} |
| 938 |
Flag is a common interface related to parsing flags in cli. For more |
| 939 |
advanced flag parsing techniques, it is recommended that this interface be |
| 940 |
implemented. |
| 941 |
|
| 942 |
var GenerateShellCompletionFlag Flag = &BoolFlag{ |
| 943 |
Name: "generate-shell-completion", |
| 944 |
Hidden: true, |
| 945 |
} |
| 946 |
GenerateShellCompletionFlag enables shell completion |
| 947 |
|
| 948 |
var HelpFlag Flag = &BoolFlag{ |
| 949 |
Name: "help", |
| 950 |
Aliases: []string{"h"}, |
| 951 |
Usage: "show help", |
| 952 |
HideDefault: true, |
| 953 |
Local: true, |
| 954 |
} |
| 955 |
HelpFlag prints the help for all commands and subcommands. Set to nil to |
| 956 |
disable the flag. The subcommand will still be added unless HideHelp or |
| 957 |
HideHelpCommand is set to true. |
| 958 |
|
| 959 |
var VersionFlag Flag = &BoolFlag{ |
| 960 |
Name: "version", |
| 961 |
Aliases: []string{"v"}, |
| 962 |
Usage: "print the version", |
| 963 |
HideDefault: true, |
| 964 |
Local: true, |
| 965 |
} |
| 966 |
VersionFlag prints the version for the application |
| 967 |
|
| 968 |
type FlagBase[T any, C any, VC ValueCreator[T, C]] struct { |
| 969 |
Name string `json:"name"` // name of the flag |
| 970 |
Category string `json:"category"` // category of the flag, if any |
| 971 |
DefaultText string `json:"defaultText"` // default text of the flag for usage purposes |
| 972 |
HideDefault bool `json:"hideDefault"` // whether to hide the default value in output |
| 973 |
Usage string `json:"usage"` // usage string for help output |
| 974 |
Sources ValueSourceChain `json:"-"` // sources to load flag value from |
| 975 |
Required bool `json:"required"` // whether the flag is required or not |
| 976 |
Hidden bool `json:"hidden"` // whether to hide the flag in help output |
| 977 |
Local bool `json:"local"` // whether the flag needs to be applied to subcommands as well |
| 978 |
Value T `json:"defaultValue"` // default value for this flag if not set by from any source |
| 979 |
Destination *T `json:"-"` // destination pointer for value when set |
| 980 |
Aliases []string `json:"aliases"` // Aliases that are allowed for this flag |
| 981 |
TakesFile bool `json:"takesFileArg"` // whether this flag takes a file argument, mainly for shell completion purposes |
| 982 |
Action func(context.Context, *Command, T) error `json:"-"` // Action callback to be called when flag is set |
| 983 |
Config C `json:"config"` // Additional/Custom configuration associated with this flag type |
| 984 |
OnlyOnce bool `json:"onlyOnce"` // whether this flag can be duplicated on the command line |
| 985 |
Validator func(T) error `json:"-"` // custom function to validate this flag value |
| 986 |
ValidateDefaults bool `json:"validateDefaults"` // whether to validate defaults or not |
| 987 |
|
| 988 |
// Has unexported fields. |
| 989 |
} |
| 990 |
FlagBase [T,C,VC] is a generic flag base which can be used as a boilerplate |
| 991 |
to implement the most common interfaces used by urfave/cli. |
| 992 |
|
| 993 |
T specifies the type |
| 994 |
C specifies the configuration required(if any for that flag type) |
| 995 |
VC specifies the value creator which creates the flag.Value emulation |
| 996 |
|
| 997 |
func (f *FlagBase[T, C, VC]) Count() int |
| 998 |
Count returns the number of times this flag has been invoked |
| 999 |
|
| 1000 |
func (f *FlagBase[T, C, V]) Get() any |
| 1001 |
|
| 1002 |
func (f *FlagBase[T, C, V]) GetCategory() string |
| 1003 |
GetCategory returns the category of the flag |
| 1004 |
|
| 1005 |
func (f *FlagBase[T, C, V]) GetDefaultText() string |
| 1006 |
GetDefaultText returns the default text for this flag |
| 1007 |
|
| 1008 |
func (f *FlagBase[T, C, V]) GetEnvVars() []string |
| 1009 |
GetEnvVars returns the env vars for this flag |
| 1010 |
|
| 1011 |
func (f *FlagBase[T, C, V]) GetUsage() string |
| 1012 |
GetUsage returns the usage string for the flag |
| 1013 |
|
| 1014 |
func (f *FlagBase[T, C, V]) GetValue() string |
| 1015 |
GetValue returns the flags value as string representation and an empty |
| 1016 |
string if the flag takes no value at all. |
| 1017 |
|
| 1018 |
func (f *FlagBase[T, C, VC]) IsBoolFlag() bool |
| 1019 |
IsBoolFlag returns whether the flag doesn't need to accept args |
| 1020 |
|
| 1021 |
func (f *FlagBase[T, C, V]) IsDefaultVisible() bool |
| 1022 |
IsDefaultVisible returns true if the flag is not hidden, otherwise false |
| 1023 |
|
| 1024 |
func (f *FlagBase[T, C, VC]) IsLocal() bool |
| 1025 |
IsLocal returns false if flag needs to be persistent across subcommands |
| 1026 |
|
| 1027 |
func (f *FlagBase[T, C, VC]) IsMultiValueFlag() bool |
| 1028 |
IsMultiValueFlag returns true if the value type T can take multiple values |
| 1029 |
from cmd line. This is true for slice and map type flags |
| 1030 |
|
| 1031 |
func (f *FlagBase[T, C, V]) IsRequired() bool |
| 1032 |
IsRequired returns whether or not the flag is required |
| 1033 |
|
| 1034 |
func (f *FlagBase[T, C, V]) IsSet() bool |
| 1035 |
IsSet returns whether or not the flag has been set through env or file |
| 1036 |
|
| 1037 |
func (f *FlagBase[T, C, V]) IsVisible() bool |
| 1038 |
IsVisible returns true if the flag is not hidden, otherwise false |
| 1039 |
|
| 1040 |
func (f *FlagBase[T, C, V]) Names() []string |
| 1041 |
Names returns the names of the flag |
| 1042 |
|
| 1043 |
func (f *FlagBase[T, C, V]) PostParse() error |
| 1044 |
PostParse populates the flag given the flag set and environment |
| 1045 |
|
| 1046 |
func (f *FlagBase[T, C, V]) PreParse() error |
| 1047 |
|
| 1048 |
func (f *FlagBase[T, C, V]) RunAction(ctx context.Context, cmd *Command) error |
| 1049 |
RunAction executes flag action if set |
| 1050 |
|
| 1051 |
func (f *FlagBase[T, C, V]) SchemaItemsType() string |
| 1052 |
SchemaItemsType returns the JSON Schema element type for slice flags. |
| 1053 |
|
| 1054 |
func (f *FlagBase[T, C, V]) SchemaType() string |
| 1055 |
SchemaType returns the JSON Schema type for the flag's value type. |
| 1056 |
|
| 1057 |
func (f *FlagBase[T, C, V]) Set(_ string, val string) error |
| 1058 |
Set applies given value from string |
| 1059 |
|
| 1060 |
func (f *FlagBase[T, C, V]) SetCategory(c string) |
| 1061 |
|
| 1062 |
func (f *FlagBase[T, C, V]) String() string |
| 1063 |
String returns a readable representation of this value (for usage defaults) |
| 1064 |
|
| 1065 |
func (f *FlagBase[T, C, V]) TakesValue() bool |
| 1066 |
TakesValue returns true if the flag takes a value, otherwise false |
| 1067 |
|
| 1068 |
func (f *FlagBase[T, C, V]) TypeName() string |
| 1069 |
TypeName returns the type of the flag. |
| 1070 |
|
| 1071 |
type FlagCategories interface { |
| 1072 |
// AddFlags adds a flag to a category, creating a new category if necessary. |
| 1073 |
AddFlag(category string, fl Flag) |
| 1074 |
// VisibleCategories returns a slice of visible flag categories sorted by name |
| 1075 |
VisibleCategories() []VisibleFlagCategory |
| 1076 |
} |
| 1077 |
FlagCategories interface allows for category manipulation |
| 1078 |
|
| 1079 |
type FlagEnvHintFunc func(envVars []string, str string) string |
| 1080 |
FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help |
| 1081 |
with the environment variable details. |
| 1082 |
|
| 1083 |
var FlagEnvHinter FlagEnvHintFunc = withEnvHint |
| 1084 |
FlagEnvHinter annotates flag help message with the environment variable |
| 1085 |
details. This is used by the default FlagStringer. |
| 1086 |
|
| 1087 |
type FlagFileHintFunc func(filePath, str string) string |
| 1088 |
FlagFileHintFunc is used by the default FlagStringFunc to annotate flag help |
| 1089 |
with the file path details. |
| 1090 |
|
| 1091 |
var FlagFileHinter FlagFileHintFunc = withFileHint |
| 1092 |
FlagFileHinter annotates flag help message with the environment variable |
| 1093 |
details. This is used by the default FlagStringer. |
| 1094 |
|
| 1095 |
type FlagNamePrefixFunc func(fullName []string, placeholder string) string |
| 1096 |
FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix |
| 1097 |
text for a flag's full name. |
| 1098 |
|
| 1099 |
var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames |
| 1100 |
FlagNamePrefixer converts a full flag name and its placeholder into the help |
| 1101 |
message flag prefix. This is used by the default FlagStringer. |
| 1102 |
|
| 1103 |
type FlagStringFunc func(Flag) string |
| 1104 |
FlagStringFunc is used by the help generation to display a flag, which is |
| 1105 |
expected to be a single line. |
| 1106 |
|
| 1107 |
var FlagStringer FlagStringFunc = stringifyFlag |
| 1108 |
FlagStringer converts a flag definition to a string. This is used by help to |
| 1109 |
display a flag. |
| 1110 |
|
| 1111 |
type FlagsByName []Flag |
| 1112 |
FlagsByName is a slice of Flag. |
| 1113 |
|
| 1114 |
func (f FlagsByName) Len() int |
| 1115 |
|
| 1116 |
func (f FlagsByName) Less(i, j int) bool |
| 1117 |
|
| 1118 |
func (f FlagsByName) Swap(i, j int) |
| 1119 |
|
| 1120 |
type Float32Arg = ArgumentBase[float32, NoConfig, floatValue[float32]] |
| 1121 |
|
| 1122 |
type Float32Args = ArgumentsBase[float32, NoConfig, floatValue[float32]] |
| 1123 |
|
| 1124 |
type Float32Flag = FlagBase[float32, NoConfig, floatValue[float32]] |
| 1125 |
|
| 1126 |
type Float32Slice = SliceBase[float32, NoConfig, floatValue[float32]] |
| 1127 |
|
| 1128 |
type Float32SliceFlag = FlagBase[[]float32, NoConfig, Float32Slice] |
| 1129 |
|
| 1130 |
type Float64Arg = ArgumentBase[float64, NoConfig, floatValue[float64]] |
| 1131 |
|
| 1132 |
type Float64Args = ArgumentsBase[float64, NoConfig, floatValue[float64]] |
| 1133 |
|
| 1134 |
type Float64Flag = FlagBase[float64, NoConfig, floatValue[float64]] |
| 1135 |
|
| 1136 |
type Float64Slice = SliceBase[float64, NoConfig, floatValue[float64]] |
| 1137 |
|
| 1138 |
type Float64SliceFlag = FlagBase[[]float64, NoConfig, Float64Slice] |
| 1139 |
|
| 1140 |
type FloatArg = ArgumentBase[float64, NoConfig, floatValue[float64]] |
| 1141 |
|
| 1142 |
type FloatArgs = ArgumentsBase[float64, NoConfig, floatValue[float64]] |
| 1143 |
|
| 1144 |
type FloatFlag = FlagBase[float64, NoConfig, floatValue[float64]] |
| 1145 |
|
| 1146 |
type FloatSlice = SliceBase[float64, NoConfig, floatValue[float64]] |
| 1147 |
|
| 1148 |
type FloatSliceFlag = FlagBase[[]float64, NoConfig, FloatSlice] |
| 1149 |
|
| 1150 |
type GenericFlag = FlagBase[Value, NoConfig, genericValue] |
| 1151 |
|
| 1152 |
type HelpPrinterCustomFunc func(w io.Writer, templ string, data any, customFunc map[string]any) |
| 1153 |
Prints help for the Command with custom template function. |
| 1154 |
|
| 1155 |
var HelpPrinterCustom HelpPrinterCustomFunc = DefaultPrintHelpCustom |
| 1156 |
HelpPrinterCustom is a function that writes the help output. It is used as |
| 1157 |
the default implementation of HelpPrinter, and may be called directly if the |
| 1158 |
ExtraInfo field is set on a Command. |
| 1159 |
|
| 1160 |
In the default implementation, if the customFuncs argument contains a |
| 1161 |
"wrapAt" key, which is a function which takes no arguments and returns an |
| 1162 |
int, this int value will be used to produce a "wrap" function used by the |
| 1163 |
default template to wrap long lines. |
| 1164 |
|
| 1165 |
type HelpPrinterFunc func(w io.Writer, templ string, data any) |
| 1166 |
HelpPrinterFunc prints help for the Command. |
| 1167 |
|
| 1168 |
var HelpPrinter HelpPrinterFunc = DefaultPrintHelp |
| 1169 |
HelpPrinter is a function that writes the help output. If not set |
| 1170 |
explicitly, this calls HelpPrinterCustom using only the default template |
| 1171 |
functions. |
| 1172 |
|
| 1173 |
If custom logic for printing help is required, this function can be |
| 1174 |
overridden. If the ExtraInfo field is defined on a Command, this function |
| 1175 |
should not be modified, as HelpPrinterCustom will be used directly in order |
| 1176 |
to capture the extra information. |
| 1177 |
|
| 1178 |
type Int16Arg = ArgumentBase[int16, IntegerConfig, intValue[int16]] |
| 1179 |
|
| 1180 |
type Int16Args = ArgumentsBase[int16, IntegerConfig, intValue[int16]] |
| 1181 |
|
| 1182 |
type Int16Flag = FlagBase[int16, IntegerConfig, intValue[int16]] |
| 1183 |
|
| 1184 |
type Int16Slice = SliceBase[int16, IntegerConfig, intValue[int16]] |
| 1185 |
|
| 1186 |
type Int16SliceFlag = FlagBase[[]int16, IntegerConfig, Int16Slice] |
| 1187 |
|
| 1188 |
type Int32Arg = ArgumentBase[int32, IntegerConfig, intValue[int32]] |
| 1189 |
|
| 1190 |
type Int32Args = ArgumentsBase[int32, IntegerConfig, intValue[int32]] |
| 1191 |
|
| 1192 |
type Int32Flag = FlagBase[int32, IntegerConfig, intValue[int32]] |
| 1193 |
|
| 1194 |
type Int32Slice = SliceBase[int32, IntegerConfig, intValue[int32]] |
| 1195 |
|
| 1196 |
type Int32SliceFlag = FlagBase[[]int32, IntegerConfig, Int32Slice] |
| 1197 |
|
| 1198 |
type Int64Arg = ArgumentBase[int64, IntegerConfig, intValue[int64]] |
| 1199 |
|
| 1200 |
type Int64Args = ArgumentsBase[int64, IntegerConfig, intValue[int64]] |
| 1201 |
|
| 1202 |
type Int64Flag = FlagBase[int64, IntegerConfig, intValue[int64]] |
| 1203 |
|
| 1204 |
type Int64Slice = SliceBase[int64, IntegerConfig, intValue[int64]] |
| 1205 |
|
| 1206 |
type Int64SliceFlag = FlagBase[[]int64, IntegerConfig, Int64Slice] |
| 1207 |
|
| 1208 |
type Int8Arg = ArgumentBase[int8, IntegerConfig, intValue[int8]] |
| 1209 |
|
| 1210 |
type Int8Args = ArgumentsBase[int8, IntegerConfig, intValue[int8]] |
| 1211 |
|
| 1212 |
type Int8Flag = FlagBase[int8, IntegerConfig, intValue[int8]] |
| 1213 |
|
| 1214 |
type Int8Slice = SliceBase[int8, IntegerConfig, intValue[int8]] |
| 1215 |
|
| 1216 |
type Int8SliceFlag = FlagBase[[]int8, IntegerConfig, Int8Slice] |
| 1217 |
|
| 1218 |
type IntArg = ArgumentBase[int, IntegerConfig, intValue[int]] |
| 1219 |
|
| 1220 |
type IntArgs = ArgumentsBase[int, IntegerConfig, intValue[int]] |
| 1221 |
|
| 1222 |
type IntFlag = FlagBase[int, IntegerConfig, intValue[int]] |
| 1223 |
|
| 1224 |
type IntSlice = SliceBase[int, IntegerConfig, intValue[int]] |
| 1225 |
|
| 1226 |
type IntSliceFlag = FlagBase[[]int, IntegerConfig, IntSlice] |
| 1227 |
|
| 1228 |
type IntegerConfig struct { |
| 1229 |
Base int |
| 1230 |
} |
| 1231 |
IntegerConfig is the configuration for all integer type flags |
| 1232 |
|
| 1233 |
type InvalidFlagAccessFunc func(context.Context, *Command, string) |
| 1234 |
InvalidFlagAccessFunc is executed when an invalid flag is accessed from the |
| 1235 |
context. |
| 1236 |
|
| 1237 |
type LocalFlag interface { |
| 1238 |
IsLocal() bool |
| 1239 |
} |
| 1240 |
LocalFlag is an interface to enable detection of flags which are local to |
| 1241 |
current command |
| 1242 |
|
| 1243 |
type MapBase[T any, C any, VC ValueCreator[T, C]] struct { |
| 1244 |
// Has unexported fields. |
| 1245 |
} |
| 1246 |
MapBase wraps map[string]T to satisfy flag.Value |
| 1247 |
|
| 1248 |
func NewMapBase[T any, C any, VC ValueCreator[T, C]](defaults map[string]T) *MapBase[T, C, VC] |
| 1249 |
NewMapBase makes a *MapBase with default values |
| 1250 |
|
| 1251 |
func (i MapBase[T, C, VC]) Create(val map[string]T, p *map[string]T, c C) Value |
| 1252 |
|
| 1253 |
func (i *MapBase[T, C, VC]) Get() any |
| 1254 |
Get returns the mapping of values set by this flag |
| 1255 |
|
| 1256 |
func (i *MapBase[T, C, VC]) Serialize() string |
| 1257 |
Serialize allows MapBase to fulfill Serializer |
| 1258 |
|
| 1259 |
func (i *MapBase[T, C, VC]) Set(value string) error |
| 1260 |
Set parses the value and appends it to the list of values |
| 1261 |
|
| 1262 |
func (i *MapBase[T, C, VC]) String() string |
| 1263 |
String returns a readable representation of this value (for usage defaults) |
| 1264 |
|
| 1265 |
func (i MapBase[T, C, VC]) ToString(t map[string]T) string |
| 1266 |
|
| 1267 |
func (i *MapBase[T, C, VC]) Value() map[string]T |
| 1268 |
Value returns the mapping of values set by this flag |
| 1269 |
|
| 1270 |
type MapSource interface { |
| 1271 |
fmt.Stringer |
| 1272 |
fmt.GoStringer |
| 1273 |
|
| 1274 |
// Lookup returns the value from the source based on key |
| 1275 |
// and if it was found |
| 1276 |
// or returns an empty string and false |
| 1277 |
Lookup(string) (any, bool) |
| 1278 |
} |
| 1279 |
MapSource is a source which can be used to look up a value based on a key |
| 1280 |
typically for use with a cli.Flag |
| 1281 |
|
| 1282 |
func NewMapSource(name string, m map[any]any) MapSource |
| 1283 |
|
| 1284 |
type MultiError interface { |
| 1285 |
error |
| 1286 |
Errors() []error |
| 1287 |
} |
| 1288 |
MultiError is an error that wraps multiple errors. |
| 1289 |
|
| 1290 |
type MutuallyExclusiveFlags struct { |
| 1291 |
// Flag list |
| 1292 |
Flags [][]Flag |
| 1293 |
|
| 1294 |
// whether this group is required |
| 1295 |
Required bool |
| 1296 |
|
| 1297 |
// Category to apply to all flags within group |
| 1298 |
Category string |
| 1299 |
} |
| 1300 |
MutuallyExclusiveFlags defines a mutually exclusive flag group Multiple |
| 1301 |
option paths can be provided out of which only one can be defined on cmdline |
| 1302 |
So for example [ --foo | [ --bar something --darth somethingelse ] ] |
| 1303 |
|
| 1304 |
type NoConfig struct{} |
| 1305 |
NoConfig is for flags which dont need a custom configuration |
| 1306 |
|
| 1307 |
type OnUsageErrorFunc func(ctx context.Context, cmd *Command, err error, isSubcommand bool) error |
| 1308 |
OnUsageErrorFunc is executed if a usage error occurs. This is useful for |
| 1309 |
displaying customized usage error messages. This function is able to replace |
| 1310 |
the original error messages. If this function is not set, the "Incorrect |
| 1311 |
usage" is displayed and the execution is interrupted. |
| 1312 |
|
| 1313 |
type RequiredFlag interface { |
| 1314 |
// whether the flag is a required flag or not |
| 1315 |
IsRequired() bool |
| 1316 |
} |
| 1317 |
RequiredFlag is an interface that allows us to mark flags as required |
| 1318 |
it allows flags required flags to be backwards compatible with the Flag |
| 1319 |
interface |
| 1320 |
|
| 1321 |
type SchemaItemsTyper interface { |
| 1322 |
// SchemaItemsType returns the JSON Schema type of elements for |
| 1323 |
// array-type flags. Returns "" for single-value or object flags. |
| 1324 |
SchemaItemsType() string |
| 1325 |
} |
| 1326 |
SchemaItemsTyper is an optional interface for multi-value flags that can |
| 1327 |
report the JSON Schema type of their elements. |
| 1328 |
|
| 1329 |
type SchemaTyper interface { |
| 1330 |
// SchemaType returns the JSON Schema type name for the value this |
| 1331 |
// flag accepts: "boolean", "integer", "number", "string", "array", |
| 1332 |
// "object". Returns "" if the flag does not map cleanly. |
| 1333 |
SchemaType() string |
| 1334 |
} |
| 1335 |
SchemaTyper is an optional interface for flags that can report their JSON |
| 1336 |
Schema type for programmatic introspection. |
| 1337 |
|
| 1338 |
type Serializer interface { |
| 1339 |
Serialize() string |
| 1340 |
} |
| 1341 |
Serializer is used to circumvent the limitations of flag.FlagSet.Set |
| 1342 |
|
| 1343 |
type ShellCompleteFunc func(context.Context, *Command) |
| 1344 |
ShellCompleteFunc is an action to execute when the shell completion flag is |
| 1345 |
set |
| 1346 |
|
| 1347 |
type SliceBase[T any, C any, VC ValueCreator[T, C]] struct { |
| 1348 |
// Has unexported fields. |
| 1349 |
} |
| 1350 |
SliceBase wraps []T to satisfy flag.Value |
| 1351 |
|
| 1352 |
func NewSliceBase[T any, C any, VC ValueCreator[T, C]](defaults ...T) *SliceBase[T, C, VC] |
| 1353 |
NewSliceBase makes a *SliceBase with default values |
| 1354 |
|
| 1355 |
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) Value |
| 1356 |
|
| 1357 |
func (i *SliceBase[T, C, VC]) Get() any |
| 1358 |
Get returns the slice of values set by this flag |
| 1359 |
|
| 1360 |
func (i *SliceBase[T, C, VC]) Serialize() string |
| 1361 |
Serialize allows SliceBase to fulfill Serializer |
| 1362 |
|
| 1363 |
func (i *SliceBase[T, C, VC]) Set(value string) error |
| 1364 |
Set parses the value and appends it to the list of values |
| 1365 |
|
| 1366 |
func (i *SliceBase[T, C, VC]) String() string |
| 1367 |
String returns a readable representation of this value (for usage defaults) |
| 1368 |
|
| 1369 |
func (i SliceBase[T, C, VC]) ToString(t []T) string |
| 1370 |
|
| 1371 |
func (i *SliceBase[T, C, VC]) Value() []T |
| 1372 |
Value returns the slice of values set by this flag |
| 1373 |
|
| 1374 |
type StringArg = ArgumentBase[string, StringConfig, stringValue] |
| 1375 |
|
| 1376 |
type StringArgs = ArgumentsBase[string, StringConfig, stringValue] |
| 1377 |
|
| 1378 |
type StringConfig struct { |
| 1379 |
// Whether to trim whitespace of parsed value |
| 1380 |
TrimSpace bool |
| 1381 |
} |
| 1382 |
StringConfig defines the configuration for string flags |
| 1383 |
|
| 1384 |
type StringFlag = FlagBase[string, StringConfig, stringValue] |
| 1385 |
|
| 1386 |
type StringMap = MapBase[string, StringConfig, stringValue] |
| 1387 |
|
| 1388 |
type StringMapArgs = ArgumentBase[map[string]string, StringConfig, StringMap] |
| 1389 |
|
| 1390 |
type StringMapFlag = FlagBase[map[string]string, StringConfig, StringMap] |
| 1391 |
|
| 1392 |
type StringSlice = SliceBase[string, StringConfig, stringValue] |
| 1393 |
|
| 1394 |
type StringSliceFlag = FlagBase[[]string, StringConfig, StringSlice] |
| 1395 |
|
| 1396 |
type SuggestCommandFunc func(commands []*Command, provided string) string |
| 1397 |
|
| 1398 |
type SuggestFlagFunc func(flags []Flag, provided string, hideHelp bool) string |
| 1399 |
|
| 1400 |
type TimestampArg = ArgumentBase[time.Time, TimestampConfig, timestampValue] |
| 1401 |
|
| 1402 |
type TimestampArgs = ArgumentsBase[time.Time, TimestampConfig, timestampValue] |
| 1403 |
|
| 1404 |
type TimestampConfig struct { |
| 1405 |
Timezone *time.Location |
| 1406 |
// Available layouts for flag value. |
| 1407 |
// |
| 1408 |
// Note that value for formats with missing year/date will be interpreted as current year/date respectively. |
| 1409 |
// |
| 1410 |
// Read more about time layouts: https://pkg.go.dev/time#pkg-constants |
| 1411 |
Layouts []string |
| 1412 |
} |
| 1413 |
TimestampConfig defines the config for timestamp flags |
| 1414 |
|
| 1415 |
type TimestampFlag = FlagBase[time.Time, TimestampConfig, timestampValue] |
| 1416 |
|
| 1417 |
type Uint16Arg = ArgumentBase[uint16, IntegerConfig, uintValue[uint16]] |
| 1418 |
|
| 1419 |
type Uint16Args = ArgumentsBase[uint16, IntegerConfig, uintValue[uint16]] |
| 1420 |
|
| 1421 |
type Uint16Flag = FlagBase[uint16, IntegerConfig, uintValue[uint16]] |
| 1422 |
|
| 1423 |
type Uint16Slice = SliceBase[uint16, IntegerConfig, uintValue[uint16]] |
| 1424 |
|
| 1425 |
type Uint16SliceFlag = FlagBase[[]uint16, IntegerConfig, Uint16Slice] |
| 1426 |
|
| 1427 |
type Uint32Arg = ArgumentBase[uint32, IntegerConfig, uintValue[uint32]] |
| 1428 |
|
| 1429 |
type Uint32Args = ArgumentsBase[uint32, IntegerConfig, uintValue[uint32]] |
| 1430 |
|
| 1431 |
type Uint32Flag = FlagBase[uint32, IntegerConfig, uintValue[uint32]] |
| 1432 |
|
| 1433 |
type Uint32Slice = SliceBase[uint32, IntegerConfig, uintValue[uint32]] |
| 1434 |
|
| 1435 |
type Uint32SliceFlag = FlagBase[[]uint32, IntegerConfig, Uint32Slice] |
| 1436 |
|
| 1437 |
type Uint64Arg = ArgumentBase[uint64, IntegerConfig, uintValue[uint64]] |
| 1438 |
|
| 1439 |
type Uint64Args = ArgumentsBase[uint64, IntegerConfig, uintValue[uint64]] |
| 1440 |
|
| 1441 |
type Uint64Flag = FlagBase[uint64, IntegerConfig, uintValue[uint64]] |
| 1442 |
|
| 1443 |
type Uint64Slice = SliceBase[uint64, IntegerConfig, uintValue[uint64]] |
| 1444 |
|
| 1445 |
type Uint64SliceFlag = FlagBase[[]uint64, IntegerConfig, Uint64Slice] |
| 1446 |
|
| 1447 |
type Uint8Arg = ArgumentBase[uint8, IntegerConfig, uintValue[uint8]] |
| 1448 |
|
| 1449 |
type Uint8Args = ArgumentsBase[uint8, IntegerConfig, uintValue[uint8]] |
| 1450 |
|
| 1451 |
type Uint8Flag = FlagBase[uint8, IntegerConfig, uintValue[uint8]] |
| 1452 |
|
| 1453 |
type Uint8Slice = SliceBase[uint8, IntegerConfig, uintValue[uint8]] |
| 1454 |
|
| 1455 |
type Uint8SliceFlag = FlagBase[[]uint8, IntegerConfig, Uint8Slice] |
| 1456 |
|
| 1457 |
type UintArg = ArgumentBase[uint, IntegerConfig, uintValue[uint]] |
| 1458 |
|
| 1459 |
type UintArgs = ArgumentsBase[uint, IntegerConfig, uintValue[uint]] |
| 1460 |
|
| 1461 |
type UintFlag = FlagBase[uint, IntegerConfig, uintValue[uint]] |
| 1462 |
|
| 1463 |
type UintSlice = SliceBase[uint, IntegerConfig, uintValue[uint]] |
| 1464 |
|
| 1465 |
type UintSliceFlag = FlagBase[[]uint, IntegerConfig, UintSlice] |
| 1466 |
|
| 1467 |
type Value interface { |
| 1468 |
flag.Value |
| 1469 |
flag.Getter |
| 1470 |
} |
| 1471 |
Value represents a value as used by cli. For now it implements the golang |
| 1472 |
flag.Value interface |
| 1473 |
|
| 1474 |
type ValueCreator[T any, C any] interface { |
| 1475 |
Create(T, *T, C) Value |
| 1476 |
ToString(T) string |
| 1477 |
} |
| 1478 |
ValueCreator is responsible for creating a flag.Value emulation as well as |
| 1479 |
custom formatting |
| 1480 |
|
| 1481 |
T specifies the type |
| 1482 |
C specifies the config for the type |
| 1483 |
|
| 1484 |
type ValueSource interface { |
| 1485 |
fmt.Stringer |
| 1486 |
fmt.GoStringer |
| 1487 |
|
| 1488 |
// Lookup returns the value from the source and if it was found |
| 1489 |
// or returns an empty string and false |
| 1490 |
Lookup() (string, bool) |
| 1491 |
} |
| 1492 |
ValueSource is a source which can be used to look up a value, typically for |
| 1493 |
use with a cli.Flag |
| 1494 |
|
| 1495 |
func EnvVar(key string) ValueSource |
| 1496 |
|
| 1497 |
func File(path string) ValueSource |
| 1498 |
|
| 1499 |
func NewMapValueSource(key string, ms MapSource) ValueSource |
| 1500 |
|
| 1501 |
type ValueSourceChain struct { |
| 1502 |
Chain []ValueSource |
| 1503 |
} |
| 1504 |
ValueSourceChain contains an ordered series of ValueSource that allows for |
| 1505 |
lookup where the first ValueSource to resolve is returned |
| 1506 |
|
| 1507 |
func EnvVars(keys ...string) ValueSourceChain |
| 1508 |
EnvVars is a helper function to encapsulate a number of envVarValueSource |
| 1509 |
together as a ValueSourceChain |
| 1510 |
|
| 1511 |
func Files(paths ...string) ValueSourceChain |
| 1512 |
Files is a helper function to encapsulate a number of fileValueSource |
| 1513 |
together as a ValueSourceChain |
| 1514 |
|
| 1515 |
func NewValueSourceChain(src ...ValueSource) ValueSourceChain |
| 1516 |
|
| 1517 |
func (vsc *ValueSourceChain) Append(other ValueSourceChain) |
| 1518 |
|
| 1519 |
func (vsc *ValueSourceChain) EnvKeys() []string |
| 1520 |
|
| 1521 |
func (vsc *ValueSourceChain) GoString() string |
| 1522 |
|
| 1523 |
func (vsc *ValueSourceChain) Lookup() (string, bool) |
| 1524 |
|
| 1525 |
func (vsc *ValueSourceChain) LookupWithSource() (string, ValueSource, bool) |
| 1526 |
|
| 1527 |
func (vsc *ValueSourceChain) String() string |
| 1528 |
|
| 1529 |
type VisibleFlag interface { |
| 1530 |
// IsVisible returns true if the flag is not hidden, otherwise false |
| 1531 |
IsVisible() bool |
| 1532 |
} |
| 1533 |
VisibleFlag is an interface that allows to check if a flag is visible |
| 1534 |
|
| 1535 |
type VisibleFlagCategory interface { |
| 1536 |
// Name returns the category name string |
| 1537 |
Name() string |
| 1538 |
// Flags returns a slice of VisibleFlag sorted by name |
| 1539 |
Flags() []Flag |
| 1540 |
} |
| 1541 |
VisibleFlagCategory is a category containing flags. |
| 1542 |
|