Documentation
¶
Overview ¶
Package flagutil contains flags that parse string lists and string maps.
Index ¶
- func DualFormatBoolVar(p *bool, name string, value bool, usage string)
- func DualFormatInt64Var(p *int64, name string, value int64, usage string)
- func DualFormatIntVar(p *int, name string, value int, usage string)
- func DualFormatStringListVar(p *[]string, name string, value []string, usage string)
- func DualFormatStringVar(p *string, name string, value string, usage string)
- func StringListVar(p *[]string, name string, defaultValue []string, usage string)
- type OptionalFlag
- type OptionalFloat64
- type OptionalString
- type StringListValue
- type StringMapValue
- type StringSetFlag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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
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
Types ¶
type OptionalFlag ¶ added in v0.11.0
OptionalFlag augements the flag.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.
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 flag.Value interface.
func (*OptionalFloat64) String ¶ added in v0.11.0
func (f *OptionalFloat64) String() string
String is part of the flag.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 flag.Value interface.
func (*OptionalString) String ¶ added in v0.11.0
func (f *OptionalString) String() string
String is part of the flag.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.
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.
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.
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.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.