Documentation
¶
Overview ¶
Package flags provides tools that are used by all commands to create deprecation flags with strict controls.
Index ¶
- Constants
- type DeprecatedFlag
- func (flag *DeprecatedFlag) AllowedSubcommandScope() bool
- func (flag *DeprecatedFlag) Evaluate(ctx context.Context) error
- func (flag *DeprecatedFlag) GetEnvVars() []string
- func (flag *DeprecatedFlag) GetHidden() bool
- func (flag *DeprecatedFlag) Names() []string
- func (flag *DeprecatedFlag) SetStrictControls(mainFlag *Flag, regControlsFn RegisterStrictControlsFunc)
- type DeprecatedFlags
- type Flag
- type NewValueFunc
- type Option
- func WithDeprecatedFlag(deprecatedFlag cli.Flag, newValueFn NewValueFunc, ...) Option
- func WithDeprecatedMovedFlag(deprecatedFlag cli.Flag, commandName string, ...) Option
- func WithDeprecatedName(flagName string, regControlsFn RegisterStrictControlsFunc) Option
- func WithDeprecatedNames(flagNames []string, regControlsFn RegisterStrictControlsFunc) Option
- func WithDeprecatedNamesEnvVars(flagNames, envVars []string, regControlsFn RegisterStrictControlsFunc) Option
- func WithDeprecatedPrefix(prefix Prefix, regControlsFn RegisterStrictControlsFunc) Option
- type Prefix
- func (prefix Prefix) Append(val string) Prefix
- func (prefix Prefix) EnvVar(name string) string
- func (prefix Prefix) EnvVars(names ...string) []string
- func (prefix Prefix) FlagName(name string) string
- func (prefix Prefix) FlagNames(names ...string) []string
- func (prefix Prefix) Prepend(val string) Prefix
- type RegisterStrictControlsFunc
- func StrictControlsByCommand(strcitControls strict.Controls, commandName string, controlNames ...string) RegisterStrictControlsFunc
- func StrictControlsByGlobalFlags(strcitControls strict.Controls, controlNames ...string) RegisterStrictControlsFunc
- func StrictControlsByMovedGlobalFlags(strcitControls strict.Controls, commandName string, controlNames ...string) RegisterStrictControlsFunc
Constants ¶
const ( // TgPrefix is an environment variable prefix. TgPrefix = "TG" // TerragruntPrefix is an environment variable deprecated prefix. TerragruntPrefix = "TERRAGRUNT" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeprecatedFlag ¶
DeprecatedFlag represents a deprecated flag that is not shown in the CLI help, but its names, envVars, are registered.
func (*DeprecatedFlag) AllowedSubcommandScope ¶
func (flag *DeprecatedFlag) AllowedSubcommandScope() bool
AllowedSubcommandScope implements `cli.Flag` interface.
func (*DeprecatedFlag) Evaluate ¶
func (flag *DeprecatedFlag) Evaluate(ctx context.Context) error
Evaluate returns an error if the one of the controls is enabled otherwise logs warning messages and returns nil.
func (*DeprecatedFlag) GetEnvVars ¶
func (flag *DeprecatedFlag) GetEnvVars() []string
GetEnvVars implements `cli.Flag` interface.
func (*DeprecatedFlag) GetHidden ¶
func (flag *DeprecatedFlag) GetHidden() bool
GetHidden implements `cli.Flag` interface.
func (*DeprecatedFlag) Names ¶
func (flag *DeprecatedFlag) Names() []string
Names implements `cli.Flag` interface.
func (*DeprecatedFlag) SetStrictControls ¶
func (flag *DeprecatedFlag) SetStrictControls(mainFlag *Flag, regControlsFn RegisterStrictControlsFunc)
SetStrictControls creates a strict control for the flag and registers it.
type DeprecatedFlags ¶
type DeprecatedFlags []*DeprecatedFlag
DeprecatedFlags are multiple of DeprecatedFlag flags.
type Flag ¶
Flag is a wrapper for `cli.Flag` that avoids displaying deprecated flags in help, but registers their flag names and environment variables.
func NewMovedFlag ¶
func NewMovedFlag(deprecatedFlag cli.Flag, newCommandName string, regControlsFn RegisterStrictControlsFunc) *Flag
func (*Flag) TakesValue ¶
TakesValue implements `cli.Flag` interface.
type NewValueFunc ¶
NewValueFunc represents a function that returns a new value for the current flag if a deprecated flag is called. Used when the current flag and the deprecated flag are of different types. For example, the string `log-format` flag must be set to `json` when deprecated bool `terragrunt-json-log` flag is used. More examples:
terragrunt-disable-log-formatting replaced with: log-format=key-value terragrunt-json-log replaced with: log-format=json terragrunt-tf-logs-to-json replaced with: log-format=json
func NewValue ¶
func NewValue(val string) NewValueFunc
NewValue returns a callback function that is used to get a new value for the current flag.
type Option ¶
type Option func(*Flag)
Option is used to set options to the `Flag`.
func WithDeprecatedFlag ¶
func WithDeprecatedFlag(deprecatedFlag cli.Flag, newValueFn NewValueFunc, regControlsFn RegisterStrictControlsFunc) Option
WithDeprecatedFlag returns an `Option` that will register the given `deprecatedFlag` as a deprecated flag. `newValueFn` is called to get a value for the new flag when this deprecated flag triggers. For example:
NewFlag(&cli.GenericFlag[string]{
Name: "log-format",
}, WithDeprecatedFlag(&cli.BoolFlag{
Name: "terragrunt-json-log",
}, flags.NewValue("json"), nil))
func WithDeprecatedMovedFlag ¶
func WithDeprecatedMovedFlag(deprecatedFlag cli.Flag, commandName string, regControlsFn RegisterStrictControlsFunc) Option
func WithDeprecatedName ¶
func WithDeprecatedName(flagName string, regControlsFn RegisterStrictControlsFunc) Option
WithDeprecatedName does the same as `WithDeprecatedNames`, but with a single name.
func WithDeprecatedNames ¶
func WithDeprecatedNames(flagNames []string, regControlsFn RegisterStrictControlsFunc) Option
WithDeprecatedNames returns an `Option` that will create a deprecated flag. The given `flagNames` names will assign both names (converting to lowercase,dash) and env vars (converting to uppercase,underscore). For example:
WithDeprecatedNames([]string{"NO_COLOR", "working-dir"}, nil)
The deprecated flag will have "no-color","working-dir" names and "NO_COLOR","WORKING_DIR" env vars.
func WithDeprecatedNamesEnvVars ¶
func WithDeprecatedNamesEnvVars(flagNames, envVars []string, regControlsFn RegisterStrictControlsFunc) Option
WithDeprecatedNamesEnvVars returns an `Option` that will create a deprecated flag, with the given `flagNames`, `envVars` assigned to the flag names and environment variables as is.
func WithDeprecatedPrefix ¶
func WithDeprecatedPrefix(prefix Prefix, regControlsFn RegisterStrictControlsFunc) Option
WithDeprecatedPrefix returns an `Option` that will create a deprecated flag with the same name as the new flag, but with the specified `prefix` prepended to the names and environment variables. Should be used with caution, as changing the name of the new flag will change the name of the deprecated flag. For example:
NewFlag(&cli.GenericFlag[string]{
Name: "no-color",
Aliases: []string{"disable-color"},
EnvVars: []string{"NO_COLOR","DISABLE_COLOR"},
}, WithDeprecatedPrefix(Prefix{"terragrunt"}, nil))
The deprecated flag will have "terragrunt-no-color","terragrunt-disable-color" names and "TERRAGRUNT_NO_COLOR","TERRAGRUNT_DISABLE_COLOR" env vars. TODO: This function is currently unused but retained for future flag deprecation needs
type Prefix ¶
type Prefix []string
Prefix helps to combine strings into flag names or environment variables in a convenient way. Can be passed to subcommands and contain the names of parent commands, thus creating env vars as a chain of "TG prefix, parent command names, command name, flag name". For example: `TG_HLC_FMT_FILE`, where `hcl` is the parent command, `fmt` is the command and `file` is a flag. Example of use:
func main () {
ParentCommand(Prefix{TgPrefix})
}
func ParentCommand(prefix Prefix) {
Command(prefix.Append("hcl"))
}
func Command(prefix Prefix) {
Flag(prefix.Append("fmt"))
}
func Flag(prefix Prefix) {
envName := prefix.EnvVar("file") // TG_HCL_FMT_FILE
}
func (Prefix) EnvVar ¶
EnvVar returns a string that is the concatenation of the slice values with the given `name`, using underscores as separators, replacing dashes with underscores, converting to uppercase.
func (Prefix) FlagName ¶
FlagName returns a string that is the concatenation of the slice values with the given `name`, using dashes as separators, replacing dashes with underscores, converting to lowercase.
type RegisterStrictControlsFunc ¶
RegisterStrictControlsFunc represents a callback func that registers the given controls in the `opts.StrictControls` stict control tree .
func StrictControlsByCommand ¶
func StrictControlsByCommand(strcitControls strict.Controls, commandName string, controlNames ...string) RegisterStrictControlsFunc
StrictControlsByCommand returns a callback function that adds the taken controls as subcontrols for the given `controlNames`. Using the given `commandName` as categories.
func StrictControlsByGlobalFlags ¶
func StrictControlsByGlobalFlags(strcitControls strict.Controls, controlNames ...string) RegisterStrictControlsFunc
StrictControlsByGlobalFlags returns a callback function that adds the taken controls as subcontrols for the given `controlNames`. And assigns the "Global Flag" category to these controls.
func StrictControlsByMovedGlobalFlags ¶
func StrictControlsByMovedGlobalFlags(strcitControls strict.Controls, commandName string, controlNames ...string) RegisterStrictControlsFunc
StrictControlsByMovedGlobalFlags returns a callback function that adds the taken controls as subcontrols for the given `controlNames`. And assigns the "Moved to other %s command global flags" category to these controls.