Documentation ¶
Overview ¶
Package flags provides tools that are used by all commands to create deprecation flags with strict controls.
Index ¶
- Constants
- type DeprecatedFlag
- type DeprecatedFlags
- type Flag
- type NewValueFunc
- type Option
- func WithDeprecatedFlag(deprecatedFlag cli.Flag, newValueFn NewValueFunc, ...) 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
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) GetEnvVars ¶
func (flag *DeprecatedFlag) GetEnvVars() []string
GetEnvVars 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 (*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 main 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 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 main flag, but with the specified `prefix` prepended to the names and environment variables. Should be used with caution, as changing the name of the main 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-disabe-color" names and "TERRAGRUNT_NO_COLOR","TERRAGRUNT_DISABLE_COLOR" env vars.
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 StrictControls ¶
func StrictControls(strcitControls strict.Controls, controlNames ...string) RegisterStrictControlsFunc
StrictControls 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 StrictControlsByGroup ¶
func StrictControlsByGroup(strcitControls strict.Controls, commandName string, controlNames ...string) RegisterStrictControlsFunc
StrictControlsByGroup returns a callback function that adds the taken controls as subcontrols for the given `controlNames`. Using the given `commandName` as categories.