Documentation ¶
Overview ¶
Package flagutil contains flags that parse string lists and string maps.
Index ¶
- Variables
- func DualFormatBoolVar(fs *pflag.FlagSet, p *bool, name string, value bool, usage string)
- func DualFormatInt64Var(fs *pflag.FlagSet, p *int64, name string, value int64, usage string)
- func DualFormatIntVar(fs *pflag.FlagSet, p *int, name string, value int, usage string)
- func DualFormatStringListVar(fs *pflag.FlagSet, p *[]string, name string, value []string, usage string)
- func DualFormatStringVar(fs *pflag.FlagSet, p *string, name string, value string, usage string)
- func DualFormatVar(fs *pflag.FlagSet, val pflag.Value, name string, usage string)
- func StringListVar(fs *pflag.FlagSet, p *[]string, name string, defaultValue []string, ...)
- type DeprecatedFloat64Seconds
- func (f DeprecatedFloat64Seconds) Clone() DeprecatedFloat64Seconds
- func (f DeprecatedFloat64Seconds) Get() time.Duration
- func (f DeprecatedFloat64Seconds) Name() string
- func (f *DeprecatedFloat64Seconds) Set(arg string) error
- func (f *DeprecatedFloat64Seconds) String() string
- func (f *DeprecatedFloat64Seconds) Type() string
- func (f *DeprecatedFloat64Seconds) UnmarshalJSON(data []byte) error
- type OptionalFlag
- type OptionalFloat64
- type OptionalString
- type StringEnum
- type StringListValue
- type StringMapValue
- type StringSetFlag
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidChoice = errors.New("invalid choice for enum")
ErrInvalidChoice is returned when parsing a value that is not a valid choice for the StringEnum flag.
Functions ¶
func DualFormatBoolVar ¶ added in v0.10.0
DualFormatBoolVar creates a flag which supports both dashes and underscores
func DualFormatInt64Var ¶ added in v0.10.0
DualFormatInt64Var creates a flag which supports both dashes and underscores
func DualFormatIntVar ¶ added in v0.10.0
DualFormatIntVar creates a flag which supports both dashes and underscores
func DualFormatStringListVar ¶ added in v0.10.0
func DualFormatStringListVar(fs *pflag.FlagSet, p *[]string, name string, value []string, usage string)
DualFormatStringListVar creates a flag which supports both dashes and underscores
func DualFormatStringVar ¶ added in v0.10.0
DualFormatStringVar creates a flag which supports both dashes and underscores
func DualFormatVar ¶ added in v0.18.0
DualFormatVar creates a flag which supports both dashes and underscores
Types ¶
type DeprecatedFloat64Seconds ¶ added in v0.17.0
type DeprecatedFloat64Seconds struct {
// contains filtered or unexported fields
}
func NewDeprecatedFloat64Seconds ¶ added in v0.17.0
func NewDeprecatedFloat64Seconds(name string, defVal time.Duration) DeprecatedFloat64Seconds
func (DeprecatedFloat64Seconds) Clone ¶ added in v0.17.0
func (f DeprecatedFloat64Seconds) Clone() DeprecatedFloat64Seconds
func (DeprecatedFloat64Seconds) Get ¶ added in v0.17.0
func (f DeprecatedFloat64Seconds) Get() time.Duration
func (DeprecatedFloat64Seconds) Name ¶ added in v0.17.0
func (f DeprecatedFloat64Seconds) Name() string
func (*DeprecatedFloat64Seconds) Set ¶ added in v0.17.0
func (f *DeprecatedFloat64Seconds) Set(arg string) error
func (*DeprecatedFloat64Seconds) String ¶ added in v0.17.0
func (f *DeprecatedFloat64Seconds) String() string
func (*DeprecatedFloat64Seconds) Type ¶ added in v0.17.0
func (f *DeprecatedFloat64Seconds) Type() string
func (*DeprecatedFloat64Seconds) UnmarshalJSON ¶ added in v0.17.0
func (f *DeprecatedFloat64Seconds) UnmarshalJSON(data []byte) error
type OptionalFlag ¶ added in v0.11.0
OptionalFlag augements the pflag.Value interface with a method to determine if a flag was set explicitly on the comand-line.
Though not part of the interface, because the return type would be different for each implementation, by convention, each implementation should define a Get() method to access the underlying value.
TODO (ajm188) - replace this interface with a generic type. c.f. https://github.com/vitessio/vitess/issues/11154.
type OptionalFloat64 ¶ added in v0.11.0
type OptionalFloat64 struct {
// contains filtered or unexported fields
}
OptionalFloat64 implements OptionalFlag for float64 values.
func NewOptionalFloat64 ¶ added in v0.11.0
func NewOptionalFloat64(val float64) *OptionalFloat64
NewOptionalFloat64 returns an OptionalFloat64 with the specified value as its starting value.
func (*OptionalFloat64) Get ¶ added in v0.11.0
func (f *OptionalFloat64) Get() float64
Get returns the underlying float64 value of this flag. If the flag was not explicitly set, this will be the initial value passed to the constructor.
func (*OptionalFloat64) IsSet ¶ added in v0.11.0
func (f *OptionalFloat64) IsSet() bool
IsSet is part of the OptionalFlag interface.
func (*OptionalFloat64) Set ¶ added in v0.11.0
func (f *OptionalFloat64) Set(arg string) error
Set is part of the pflag.Value interface.
func (*OptionalFloat64) String ¶ added in v0.11.0
func (f *OptionalFloat64) String() string
String is part of the pflag.Value interface.
func (*OptionalFloat64) Type ¶ added in v0.15.0
func (f *OptionalFloat64) Type() string
Type is part of the pflag.Value interface.
type OptionalString ¶ added in v0.11.0
type OptionalString struct {
// contains filtered or unexported fields
}
OptionalString implements OptionalFlag for string values.
func NewOptionalString ¶ added in v0.11.0
func NewOptionalString(val string) *OptionalString
NewOptionalString returns an OptionalString with the specified value as its starting value.
func (*OptionalString) Get ¶ added in v0.11.0
func (f *OptionalString) Get() string
Get returns the underlying string value of this flag. If the flag was not explicitly set, this will be the initial value passed to the constructor.
func (*OptionalString) IsSet ¶ added in v0.11.0
func (f *OptionalString) IsSet() bool
IsSet is part of the OptionalFlag interface.
func (*OptionalString) Set ¶ added in v0.11.0
func (f *OptionalString) Set(arg string) error
Set is part of the pflag.Value interface.
func (*OptionalString) String ¶ added in v0.11.0
func (f *OptionalString) String() string
String is part of the pflag.Value interface.
func (*OptionalString) Type ¶ added in v0.15.0
func (f *OptionalString) Type() string
Type is part of the pflag.Value interface.
type StringEnum ¶ added in v0.17.0
type StringEnum struct {
// contains filtered or unexported fields
}
StringEnum provides a string-like flag value that raises an error if given a value not in the set of allowed choices.
This parse-time validation can be case-sensitive or not, depending on which constructor (NewStringEnum vs NewCaseInsensitiveStringEnum) was used.
func NewCaseInsensitiveStringEnum ¶ added in v0.17.0
func NewCaseInsensitiveStringEnum(name string, initialValue string, choices []string) *StringEnum
NewCaseInsensitiveStringEnum returns a new string enum flag with the given name, default, and choices.
Parse-time validation is case-insensitive.
func NewStringEnum ¶ added in v0.17.0
func NewStringEnum(name string, initialValue string, choices []string) *StringEnum
NewStringEnum returns a new string enum flag with the given name, default, and choices.
Parse-time validation is case-sensitive.
func (*StringEnum) Set ¶ added in v0.17.0
func (s *StringEnum) Set(arg string) error
Set is part of the pflag.Value interface.
func (*StringEnum) String ¶ added in v0.17.0
func (s *StringEnum) String() string
String is part of the pflag.Value interface.
func (*StringEnum) Type ¶ added in v0.17.0
func (s *StringEnum) Type() string
Type is part of the pflag.Value interface.
type StringListValue ¶
type StringListValue []string
StringListValue is a []string flag that accepts a comma separated list of elements. To include an element containing a comma, quote it with a backslash '\'.
func (StringListValue) Get ¶
func (value StringListValue) Get() any
Get returns the []string value of this flag.
func (*StringListValue) Set ¶
func (value *StringListValue) Set(v string) error
Set sets the value of this flag from parsing the given string.
func (StringListValue) String ¶
func (value StringListValue) String() string
String returns the string representation of this flag.
func (StringListValue) Type ¶ added in v0.15.0
func (value StringListValue) Type() string
type StringMapValue ¶
StringMapValue is a map[string]string flag. It accepts a comma-separated list of key value pairs, of the form key:value. The keys cannot contain colons.
TODO (andrew): Look into whether there's a native pflag Flag type that we can use/transition to instead.
func (StringMapValue) Get ¶
func (value StringMapValue) Get() any
Get returns the map[string]string value of this flag.
func (*StringMapValue) Set ¶
func (value *StringMapValue) Set(v string) error
Set sets the value of this flag from parsing the given string.
func (StringMapValue) String ¶
func (value StringMapValue) String() string
String returns the string representation of this flag.
func (StringMapValue) Type ¶ added in v0.15.0
func (value StringMapValue) Type() string
Type is part of the pflag.Value interface.
type StringSetFlag ¶ added in v0.11.0
type StringSetFlag struct {
// contains filtered or unexported fields
}
StringSetFlag can be used to collect multiple instances of a flag into a set of values.
For example, defining the following:
var x flagutil.StringSetFlag flag.Var(&x, "foo", "")
And then specifying "-foo x -foo y -foo x", will result in a set of {x, y}.
In addition to implemnting the standard flag.Value interface, it also provides an implementation of pflag.Value, so it is usable in libraries like cobra.
func (*StringSetFlag) Set ¶ added in v0.11.0
func (set *StringSetFlag) Set(s string) error
Set is part of the pflag.Value and flag.Value interfaces.
func (*StringSetFlag) String ¶ added in v0.11.0
func (set *StringSetFlag) String() string
String is part of the pflag.Value and flag.Value interfaces.
func (*StringSetFlag) ToSet ¶ added in v0.11.0
func (set *StringSetFlag) ToSet() sets.Set[string]
ToSet returns the underlying string set, or an empty set if the underlying set is nil.
func (*StringSetFlag) Type ¶ added in v0.11.0
func (set *StringSetFlag) Type() string
Type is part of the pflag.Value interface.