Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidValue = "invalid value %q, allowed values are: %s"
)
Functions ¶
Types ¶
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
Flag is a custom flag type that restricts its value to a predefined set of allowed strings.
func NewFlag ¶
func NewFlag( defaultValue string, value *string, allowed []string, name string, usage string, ) *Flag
NewFlag creates a new Flag with a default value and a list of allowed values.
Parameters:
defaultValue - the default value for the flag. value - the default value for the flag. allowed - slice of allowed string values. name - the name of the flag. usage - the usage description for the flag.
Returns:
A pointer to the created Flag.
func (*Flag) Allowed ¶
Allowed returns the list of allowed values for the flag.
Returns:
The allowed values.
func (*Flag) Default ¶ added in v0.3.4
Default returns the default value of the flag.
Returns:
The default value of the flag as a string.
func (*Flag) Set ¶
Set validates and sets the flag's value.
Parameters:
value - the value to set.
Returns:
An error if the value is not allowed, otherwise nil.
func (*Flag) SetFlag ¶ added in v0.3.4
func (f *Flag) SetFlag()
SetFlag registers the custom flag with the standard flag package.
Click to show internal directories.
Click to hide internal directories.