Documentation
¶
Overview ¶
Package cli provides functionality for the Terragrunt CLI.
Index ¶
- Constants
- Variables
- func ApplyFlag(flag Flag, set *libflag.FlagSet) error
- func LexicographicLess(i, j string) bool
- func ShowAppHelp(ctx *Context) error
- func ShowCommandHelp(ctx *Context) error
- func ShowCompletions(ctx *Context) error
- func ShowVersion(ctx *Context) error
- type ActionFunc
- type App
- type Args
- func (args Args) CommandName() string
- func (args Args) CommandNameN(n int) string
- func (args Args) Contains(target string) bool
- func (args Args) First() string
- func (args Args) Get(n int) string
- func (args Args) Last() string
- func (args Args) Len() int
- func (args Args) Normalize(acts ...NormalizeActsType) Args
- func (args Args) Present() bool
- func (args Args) Remove(name string) Args
- func (args Args) Second() string
- func (args Args) Slice() []string
- func (args Args) Split(sep string) (Args, Args)
- func (args Args) SubCommandName() string
- func (args Args) Tail() Args
- func (args Args) WithoutBuiltinCmdSep() Args
- type AutocompleteInstaller
- type BoolFlag
- func (flag *BoolFlag) Apply(set *libflag.FlagSet) error
- func (flag *BoolFlag) GetCategory() string
- func (flag *BoolFlag) GetDefaultText() string
- func (flag *BoolFlag) GetEnvVars() []string
- func (flag *BoolFlag) GetHidden() bool
- func (flag *BoolFlag) GetUsage() string
- func (flag *BoolFlag) GetValue() string
- func (flag *BoolFlag) LookupEnv(envVar string) []string
- func (flag *BoolFlag) Names() []string
- func (flag *BoolFlag) RunAction(ctx *Context) error
- func (flag *BoolFlag) SplitValue(val string) []string
- func (flag *BoolFlag) String() string
- func (flag *BoolFlag) TakesValue() bool
- func (flag *BoolFlag) Value() FlagValue
- type Command
- func (cmd *Command) HasName(name string) bool
- func (cmd *Command) Names() []string
- func (cmd *Command) Run(ctx *Context, args Args) (err error)
- func (cmd *Command) Subcommand(name string) *Command
- func (cmd *Command) VisibleFlags() Flags
- func (cmd *Command) VisibleSubcommands() []*cli.Command
- func (cmd *Command) WrapAction(fn func(ctx *Context, action ActionFunc) error) *Command
- type Commands
- func (commands *Commands) Add(cmd *Command)
- func (commands Commands) Filter(names []string) Commands
- func (commands Commands) Get(name string) *Command
- func (commands Commands) Len() int
- func (commands Commands) Less(i, j int) bool
- func (commands Commands) SkipRunning() Commands
- func (commands Commands) Swap(i, j int)
- func (commands Commands) VisibleCommands() []*cli.Command
- func (commands Commands) WrapAction(fn func(ctx *Context, action ActionFunc) error) Commands
- type CompleteFunc
- type Context
- type ExitCode
- type ExitCoder
- type ExitErrHandlerFunc
- type Flag
- type FlagActionFunc
- type FlagSetterFunc
- type FlagValue
- type FlagValueGetter
- type FlagVariable
- type Flags
- func (flags Flags) Add(newFlags ...Flag) Flags
- func (flags Flags) Apply(flagSet *libflag.FlagSet) error
- func (flags Flags) Filter(names ...string) Flags
- func (flags Flags) Get(name string) Flag
- func (flags Flags) Len() int
- func (flags Flags) Less(i, j int) bool
- func (flags Flags) RunActions(ctx *Context) error
- func (flags Flags) Sort() Flags
- func (flags Flags) Swap(i, j int)
- func (flags Flags) VisibleFlags() Flags
- type GenericFlag
- func (flag *GenericFlag[T]) Apply(set *libflag.FlagSet) error
- func (flag *GenericFlag) GetCategory() string
- func (flag *GenericFlag[T]) GetDefaultText() string
- func (flag *GenericFlag[T]) GetEnvVars() []string
- func (flag *GenericFlag[T]) GetHidden() bool
- func (flag *GenericFlag[T]) GetUsage() string
- func (flag *GenericFlag) GetValue() string
- func (flag *GenericFlag) LookupEnv(envVar string) []string
- func (flag *GenericFlag[T]) Names() []string
- func (flag *GenericFlag[T]) RunAction(ctx *Context) error
- func (flag *GenericFlag) SplitValue(val string) []string
- func (flag *GenericFlag[T]) String() string
- func (flag *GenericFlag) TakesValue() bool
- func (flag *GenericFlag) Value() FlagValue
- type GenericType
- type HelpFunc
- type InvalidCommandNameError
- type InvalidKeyValueError
- type InvalidValueError
- type LookupEnvFuncType
- type MapFlag
- func (flag *MapFlag[K, V]) Apply(set *libflag.FlagSet) error
- func (flag *MapFlag) GetCategory() string
- func (flag *MapFlag[K, V]) GetDefaultText() string
- func (flag *MapFlag[K, V]) GetEnvVars() []string
- func (flag *MapFlag[K, V]) GetHidden() bool
- func (flag *MapFlag[K, V]) GetUsage() string
- func (flag *MapFlag) GetValue() string
- func (flag *MapFlag) LookupEnv(envVar string) []string
- func (flag *MapFlag[K, V]) Names() []string
- func (flag *MapFlag[K, V]) RunAction(ctx *Context) error
- func (flag *MapFlag) SplitValue(val string) []string
- func (flag *MapFlag[K, V]) String() string
- func (flag *MapFlag) TakesValue() bool
- func (flag *MapFlag) Value() FlagValue
- type MapFlagKeyType
- type MapFlagSetterFunc
- type MapFlagValueType
- type NormalizeActsType
- type SliceFlag
- func (flag *SliceFlag[T]) Apply(set *libflag.FlagSet) error
- func (flag *SliceFlag) GetCategory() string
- func (flag *SliceFlag[T]) GetDefaultText() string
- func (flag *SliceFlag[T]) GetEnvVars() []string
- func (flag *SliceFlag[T]) GetHidden() bool
- func (flag *SliceFlag[T]) GetUsage() string
- func (flag *SliceFlag) GetValue() string
- func (flag *SliceFlag) LookupEnv(envVar string) []string
- func (flag *SliceFlag[T]) Names() []string
- func (flag *SliceFlag[T]) RunAction(ctx *Context) error
- func (flag *SliceFlag) SplitValue(val string) []string
- func (flag *SliceFlag[T]) String() string
- func (flag *SliceFlag) TakesValue() bool
- func (flag *SliceFlag) Value() FlagValue
- type SliceFlagType
- type SplitterFunc
- type UndefinedFlagError
- type Value
Constants ¶
const (
BuiltinCmdSep = "--"
)
Variables ¶
var ( // AppVersionTemplate is the text template for the Default version topic. AppVersionTemplate = "" // AppHelpTemplate is the text template for the Default help topic. AppHelpTemplate = "" // CommandHelpTemplate is the text template for the command help topic. CommandHelpTemplate = "" )
var ( MapFlagEnvVarSep = "," MapFlagKeyValSep = "=" )
var DefaultComplete = defaultComplete
var ( // FlagSplitter uses to separate arguments and env vars with multiple values. FlagSplitter = strings.Split )
var FlagStringer = cli.FlagStringer //nolint:gochecknoglobals
FlagStringer converts a flag definition to a string. This is used by help to display a flag.
var (
SliceFlagEnvVarSep = ","
)
Functions ¶
func LexicographicLess ¶
LexicographicLess compares strings alphabetically considering case.
func ShowCommandHelp ¶
ShowCommandHelp prints command help for the given `ctx`.
func ShowCompletions ¶
ShowCompletions prints the lists of commands within a given context
func ShowVersion ¶
Types ¶
type ActionFunc ¶
ActionFunc is the action to execute when no commands/subcommands are specified.
type App ¶
type App struct { *cli.App // Examples is list of examples of using the App in the help. Examples []string // List of commands to execute Commands Commands // List of flags to parse Flags Flags // CustomAppVersionTemplate text template for app version topic. CustomAppVersionTemplate string // Contributor Author string // The function to call when checking for command completions Complete CompleteFunc // An action to execute before any subcommands are run, but after the context is ready // If a non-nil error is returned, no subcommands are run Before ActionFunc // An action to execute after any subcommands are run, but after the subcommand has finished After ActionFunc // The action to execute when no subcommands are specified Action ActionFunc // OsExiter is the function used when the app exits. If not set defaults to os.Exit. OsExiter func(code int) // ExitErrHandler processes any error encountered while running an App before // it is returned to the caller. If no function is provided, HandleExitCoder // is used as the default behavior. ExitErrHandler ExitErrHandlerFunc // Autocomplete enables or disables subcommand auto-completion support. // This is enabled by default when NewApp is called. Otherwise, this // must enabled explicitly. // // Autocomplete requires the "Name" option to be set on CLI. This name // should be set exactly to the binary name that is autocompleted. Autocomplete bool // AutocompleteInstallFlag and AutocompleteUninstallFlag are the global flag // names for installing and uninstalling the autocompletion handlers // for the user's shell. The flag should omit the hyphen(s) in front of // the value. Both single and double hyphens will automatically be supported // for the flag name. These default to `autocomplete-install` and // `autocomplete-uninstall` respectively. AutocompleteInstallFlag string AutocompleteUninstallFlag string // Autocompletion is supported via the github.com/posener/complete // library. This library supports bash, zsh and fish. To add support // for other shells, please see that library. AutocompleteInstaller AutocompleteInstaller }
App is a wrapper for `urfave`'s `cli.App` struct. It should be created with the cli.NewApp() function. The main purpose of this wrapper is to parse commands and flags in the way we need, namely, if during parsing we find undefined commands or flags, instead of returning an error, we consider them as arguments, regardless of their position among the others registered commands and flags.
For example, CLI command: `terragrunt run-all apply --terragrunt-log-level trace --auto-approve --terragrunt-non-interactive` The `App` will runs the registered command `run-all`, define the registered flags `--terragrunt-log-level`, `--terragrunt-non-interactive`, and define args `apply --auto-approve` which can be obtained from the App context, ctx.Args().Slice()
func (*App) AddCommands ¶
AddCommands adds new commands.
func (*App) Run ¶
Run is the entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination.
func (*App) RunContext ¶
RunContext is like Run except it takes a Context that will be passed to its commands and sub-commands. Through this, you can propagate timeouts and cancellation requests
func (*App) VisibleCommands ¶
func (app *App) VisibleCommands() []*cli.Command
VisibleCommands returns a slice of the Commands used for help.
func (*App) VisibleFlags ¶
VisibleFlags returns a slice of the Flags used for help.
type Args ¶
type Args []string
Args provides convenient access to CLI arguments.
func (Args) CommandName ¶
CommandName returns the first arg that starts without a dash `-`, otherwise that means the args do not consist any command and an empty string is returned.
func (Args) CommandNameN ¶
CommandNameN returns the nth argument from `args` that starts without a dash `-`.
func (Args) Normalize ¶
func (args Args) Normalize(acts ...NormalizeActsType) Args
Normalize formats the arguments according to the given actions. if the given act is:
`SingleDashFlag` - converts all arguments containing double dashes to single dashes `DoubleDashFlag` - converts all arguments containing single dashes to double dashes
func (Args) SubCommandName ¶
SubCommandName returns the second arg that starts without a dash `-`, otherwise that means the args do not consist a subcommand and an empty string is returned.
func (Args) Tail ¶
Tail returns the rest of the arguments (not the first one) or else an empty string slice.
func (Args) WithoutBuiltinCmdSep ¶
type AutocompleteInstaller ¶
AutocompleteInstaller is an interface to be implemented to perform the autocomplete installation and uninstallation with a CLI.
This interface is not exported because it only exists for unit tests to be able to test that the installation is called properly.
type BoolFlag ¶
type BoolFlag struct { // The name of the flag. Name string // The default value of the flag to display in the help, if it is empty, the value is taken from `Destination`. DefaultText string // A short usage description to display in help. Usage string // Aliases are usually used for the short flag name, like `-h`. Aliases []string // The names of the env variables that are parsed and assigned to `Destination` before the flag value. EnvVars []string // Action is a function that is called when the flag is specified. It is executed only after all command flags have been parsed. Action FlagActionFunc[bool] // FlagSetterFunc represents function type that is called when the flag is specified. // Executed during value parsing, in case of an error the returned error is wrapped with the flag or environment variable name. Setter FlagSetterFunc[bool] // Destination ia a pointer to which the value of the flag or env var is assigned. // It also uses as the default value displayed in the help. Destination *bool // If set to true, then the assigned flag value will be inverted Negative bool // Hidden hides the flag from the help, if set to true. Hidden bool // contains filtered or unexported fields }
func (*BoolFlag) GetCategory ¶
func (flag *BoolFlag) GetCategory() string
GetCategory returns the category for the flag. Implements `cli.DocGenerationFlag.GetCategory` required to generate help.
func (*BoolFlag) GetDefaultText ¶
GetDefaultText returns the flags value as string representation and an empty string if the flag takes no value at all.
func (*BoolFlag) GetEnvVars ¶
GetEnvVars implements `cli.Flag` interface.
func (*BoolFlag) GetValue ¶
func (flag *BoolFlag) GetValue() string
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all. Implements `cli.DocGenerationFlag.GetValue` required to generate help.
func (*BoolFlag) SplitValue ¶
func (*BoolFlag) String ¶
String returns a readable representation of this value (for usage defaults).
func (*BoolFlag) TakesValue ¶
TakesValue returns true of the flag takes a value, otherwise false. Implements `cli.DocGenerationFlag.TakesValue` required to generate help.
type Command ¶
type Command struct { // Name is the command name. Name string // Aliases is a list of aliases for the command. Aliases []string // Usage is a short description of the usage of the command. Usage string // UsageText is custom text to show on the `Usage` section of help. UsageText string // Description is a longer explanation of how the command works. Description string // Examples is list of examples of using the command in the help. Examples []string // Flags is list of flags to parse. Flags Flags // ErrorOnUndefinedFlag causes the application to exit and return an error on any undefined flag. ErrorOnUndefinedFlag bool // Full name of cmd for help, defaults to full cmd name, including parent commands. HelpName string // if this is a root "special" cmd IsRoot bool // Boolean to hide this cmd from help Hidden bool // CustomHelpTemplate the text template for the cmd help topic. // cli.go uses text/template to render templates. You can // render custom help text by setting this variable. CustomHelpTemplate string // CustomHelp is a func that is executed when help for a command needs to be displayed. CustomHelp HelpFunc // List of child commands Subcommands Commands // Treat all flags as normal arguments if true SkipFlagParsing bool // Boolean to disable the parsing command, but it will still be shown in the help. SkipRunning bool // The function to call when checking for command completions Complete CompleteFunc // An action to execute before any subcommands are run, but after the context is ready // If a non-nil error is returned, no subcommands are run Before ActionFunc // An action to execute after any subcommands are run, but after the subcommand has finished After ActionFunc // The action to execute when no subcommands are specified Action ActionFunc }
func (*Command) Run ¶
Run parses the given args for the presence of flags as well as subcommands. If this is the final command, starts its execution.
func (*Command) Subcommand ¶
Subcommand returns a subcommand that matches the given name.
func (*Command) VisibleFlags ¶
VisibleFlags returns a slice of the Flags, used by `urfave/cli` package to generate help.
func (*Command) VisibleSubcommands ¶
func (cmd *Command) VisibleSubcommands() []*cli.Command
VisibleSubcommands returns a slice of the Commands with Hidden=false. Used by `urfave/cli` package to generate help.
func (*Command) WrapAction ¶
func (cmd *Command) WrapAction(fn func(ctx *Context, action ActionFunc) error) *Command
type Commands ¶
type Commands []*Command
func (Commands) SkipRunning ¶
SkipRunning prevents running commands as the final commands, but keep showing them in help.
func (Commands) VisibleCommands ¶
func (commands Commands) VisibleCommands() []*cli.Command
VisibleCommands returns a slice of the Commands with Hidden=false. Used by `urfave/cli` package to generate help.
func (Commands) WrapAction ¶
func (commands Commands) WrapAction(fn func(ctx *Context, action ActionFunc) error) Commands
type CompleteFunc ¶
CompleteFunc is an action to execute when the shell completion flag is set
type Context ¶
type Context struct { context.Context *App Command *Command // contains filtered or unexported fields }
Context can be used to retrieve context-specific args and parsed command-line options.
func (*Context) NewCommandContext ¶
type ExitCode ¶
type ExitCode byte
ExitCode is a number between 0 and 255, which is returned by any Unix command when it returns control to its parent process.
type ExitCoder ¶
ExitCoder is the interface checked by `App` and `Command` for a custom exit code.
func NewExitError ¶
NewExitError calls Exit to create a new ExitCoder.
type ExitErrHandlerFunc ¶
ExitErrHandlerFunc is executed if provided in order to handle exitError values returned by Actions and Before/After functions.
type FlagActionFunc ¶
FlagActionFunc represents function type that is called when the flag is specified. Executed after flag have been parsed and assigned to the `Destination` field.
type FlagSetterFunc ¶
FlagSetterFunc represents function type that is called when the flag is specified. Unlike `FlagActionFunc` where the function is called after the value has been parsed and assigned to the `Destination` field, `FlagSetterFunc` is called earlier, during the variable parsing. if `FlagSetterFunc` returns the error, it will be wrapped with the flag or environment variable name. Example: `fmt.Errorf("invalid value \"invalid-value\" for env var TG_ENV_VAR: %w", err)` Therefore, using `FlagSetterFunc` is preferable to `FlagActionFunc` when you need to indicate in the error from where the value came from. If the flag has multiple values, `FlagSetterFunc` will be called for each value.
type FlagValue ¶
type FlagValue interface { fmt.Stringer Get() any Set(str string) error Getter(name string) FlagValueGetter GetName() string GetInitialTextValue() string // IsSet returns true if the flag was set either by env var or CLI arg. IsSet() bool // IsSet returns true if the flag was by CLI arg. IsArgSet() bool // IsEnvSet returns true if the flag was set by env var. IsEnvSet() bool // optional interface to indicate boolean flags that can be // supplied without "=value" text IsBoolFlag() bool }
type FlagVariable ¶
type FlagVariable[T any] interface { libflag.Getter Clone(dest *T) FlagVariable[T] }
type Flags ¶
type Flags []Flag
func (Flags) RunActions ¶
func (Flags) VisibleFlags ¶
VisibleFlags returns a slice of the Flags. Used by `urfave/cli` package to generate help.
type GenericFlag ¶
type GenericFlag[T GenericType] struct { // The name of the flag. Name string // The default value of the flag to display in the help, if it is empty, the value is taken from `Destination`. DefaultText string // A short usage description to display in help. Usage string // Aliases are usually used for the short flag name, like `-h`. Aliases []string // The names of the env variables that are parsed and assigned to `Destination` before the flag value. EnvVars []string // Action is a function that is called when the flag is specified. It is executed only after all command flags have been parsed. Action FlagActionFunc[T] // Setter allows to set a value to any type by calling its `func(bool) error` function. Setter FlagSetterFunc[T] // Destination is a pointer to which the value of the flag or env var is assigned. // It also uses as the default value displayed in the help. Destination *T // Hidden hides the flag from the help, if set to true. Hidden bool // contains filtered or unexported fields }
func (*GenericFlag[T]) Apply ¶
func (flag *GenericFlag[T]) Apply(set *libflag.FlagSet) error
Apply applies Flag settings to the given flag set.
func (*GenericFlag) GetCategory ¶
func (flag *GenericFlag) GetCategory() string
GetCategory returns the category for the flag. Implements `cli.DocGenerationFlag.GetCategory` required to generate help.
func (*GenericFlag[T]) GetDefaultText ¶
func (flag *GenericFlag[T]) GetDefaultText() string
GetDefaultText returns the flags value as string representation and an empty string if the flag takes no value at all.
func (*GenericFlag[T]) GetEnvVars ¶
func (flag *GenericFlag[T]) GetEnvVars() []string
GetEnvVars implements `cli.Flag` interface.
func (*GenericFlag[T]) GetHidden ¶
func (flag *GenericFlag[T]) GetHidden() bool
GetHidden returns true if the flag should be hidden from the help.
func (*GenericFlag[T]) GetUsage ¶
func (flag *GenericFlag[T]) GetUsage() string
GetUsage returns the usage string for the flag.
func (*GenericFlag) GetValue ¶
func (flag *GenericFlag) GetValue() string
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all. Implements `cli.DocGenerationFlag.GetValue` required to generate help.
func (*GenericFlag[T]) Names ¶
func (flag *GenericFlag[T]) Names() []string
Names returns the names of the flag.
func (*GenericFlag[T]) RunAction ¶
func (flag *GenericFlag[T]) RunAction(ctx *Context) error
RunAction implements ActionableFlag.RunAction
func (*GenericFlag) SplitValue ¶
func (*GenericFlag[T]) String ¶
func (flag *GenericFlag[T]) String() string
String returns a readable representation of this value (for usage defaults).
func (*GenericFlag) TakesValue ¶
func (flag *GenericFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false. Implements `cli.DocGenerationFlag.TakesValue` required to generate help.
type InvalidCommandNameError ¶
type InvalidCommandNameError string
func (InvalidCommandNameError) Error ¶
func (cmdName InvalidCommandNameError) Error() string
type InvalidKeyValueError ¶
type InvalidKeyValueError struct {
// contains filtered or unexported fields
}
func NewInvalidKeyValueError ¶
func NewInvalidKeyValueError(sep, value string) *InvalidKeyValueError
func (InvalidKeyValueError) Error ¶
func (err InvalidKeyValueError) Error() string
type InvalidValueError ¶
type InvalidValueError struct {
// contains filtered or unexported fields
}
InvalidValueError is used to wrap errors from `strconv` to make the error message more user friendly.
func (InvalidValueError) Error ¶
func (err InvalidValueError) Error() string
func (InvalidValueError) Unwrap ¶
func (err InvalidValueError) Unwrap() error
type LookupEnvFuncType ¶
type MapFlag ¶
type MapFlag[K MapFlagKeyType, V MapFlagValueType] struct { // The name of the flag. Name string // The default value of the flag to display in the help, if it is empty, the value is taken from `Destination`. DefaultText string // A short usage description to display in help. Usage string // Aliases are usually used for the short flag name, like `-h`. Aliases []string // Action is a function that is called when the flag is specified. It is executed only after all command flags have been parsed. Action FlagActionFunc[map[K]V] // FlagSetterFunc represents function type that is called when the flag is specified. // Executed during value parsing, in case of an error the returned error is wrapped with the flag or environment variable name. Setter MapFlagSetterFunc[K, V] // The names of the env variables that are parsed and assigned to `Destination` before the flag value. EnvVars []string // DisableEnvVar disables the creation of the environment variable by default. DisableEnvVar bool // Destination is a pointer to which the value of the flag or env var is assigned. // It also uses as the default value displayed in the help. Destination *map[K]V // The func used to split the EvnVar, by default `strings.Split` Splitter SplitterFunc // The EnvVarSep value is passed to the Splitter function as an argument to split the args. EnvVarSep string // The KeyValSep value is passed to the Splitter function as an argument to split `key` and `val` of the arg. KeyValSep string // Hidden hides the flag from the help, if set to true. Hidden bool // contains filtered or unexported fields }
MapFlag is a key value flag.
func (*MapFlag) GetCategory ¶
func (flag *MapFlag) GetCategory() string
GetCategory returns the category for the flag. Implements `cli.DocGenerationFlag.GetCategory` required to generate help.
func (*MapFlag[K, V]) GetDefaultText ¶
GetDefaultText returns the flags value as string representation and an empty string if the flag takes no value at all.
func (*MapFlag[K, V]) GetEnvVars ¶
GetEnvVars implements `cli.Flag` interface.
func (*MapFlag[K, V]) GetHidden ¶
GetHidden returns true if the flag should be hidden from the help.
func (*MapFlag) GetValue ¶
func (flag *MapFlag) GetValue() string
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all. Implements `cli.DocGenerationFlag.GetValue` required to generate help.
func (*MapFlag) SplitValue ¶
func (*MapFlag[K, V]) String ¶
String returns a readable representation of this value (for usage defaults).
func (*MapFlag) TakesValue ¶
func (flag *MapFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false. Implements `cli.DocGenerationFlag.TakesValue` required to generate help.
type MapFlagKeyType ¶
type MapFlagKeyType interface { GenericType }
type MapFlagSetterFunc ¶
type MapFlagValueType ¶
type MapFlagValueType interface { GenericType | bool }
type NormalizeActsType ¶
type NormalizeActsType byte
const ( SingleDashFlag NormalizeActsType = iota DoubleDashFlag )
type SliceFlag ¶
type SliceFlag[T SliceFlagType] struct { // The name of the flag. Name string // The default value of the flag to display in the help, if it is empty, the value is taken from `Destination`. DefaultText string // A short usage description to display in help. Usage string // Aliases are usually used for the short flag name, like `-h`. Aliases []string // The names of the env variables that are parsed and assigned to `Destination` before the flag value. EnvVars []string // Action is a function that is called when the flag is specified. It is executed only after all command flags have been parsed. Action FlagActionFunc[[]T] // FlagSetterFunc represents function type that is called when the flag is specified. // Executed during value parsing, in case of an error the returned error is wrapped with the flag or environment variable name. Setter FlagSetterFunc[T] // Destination is a pointer to which the value of the flag or env var is assigned. // It also uses as the default value displayed in the help. Destination *[]T // The func used to split the EvnVar, by default `strings.Split` Splitter SplitterFunc // The EnvVarSep value is passed to the Splitter function as an argument. EnvVarSep string // Hidden hides the flag from the help, if set to true. Hidden bool // contains filtered or unexported fields }
SliceFlag is a multiple flag.
func (*SliceFlag) GetCategory ¶
func (flag *SliceFlag) GetCategory() string
GetCategory returns the category for the flag. Implements `cli.DocGenerationFlag.GetCategory` required to generate help.
func (*SliceFlag[T]) GetDefaultText ¶
GetDefaultText returns the flags value as string representation and an empty string if the flag takes no value at all.
func (*SliceFlag[T]) GetEnvVars ¶
GetEnvVars implements `cli.Flag` interface.
func (*SliceFlag) GetValue ¶
func (flag *SliceFlag) GetValue() string
GetValue returns the flags value as string representation and an empty string if the flag takes no value at all. Implements `cli.DocGenerationFlag.GetValue` required to generate help.
func (*SliceFlag) SplitValue ¶
func (*SliceFlag[T]) String ¶
String returns a readable representation of this value (for usage defaults).
func (*SliceFlag) TakesValue ¶
func (flag *SliceFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false. Implements `cli.DocGenerationFlag.TakesValue` required to generate help.
type SliceFlagType ¶
type SliceFlagType interface { GenericType }
type SplitterFunc ¶
SplitterFunc is used to parse flags containing multiple values.
type UndefinedFlagError ¶
type UndefinedFlagError string
func (UndefinedFlagError) Error ¶
func (err UndefinedFlagError) Error() string