Documentation
¶
Index ¶
- Variables
- type AllowedFunc
- type EnumFlag
- type EnumSliceFlag
- func NewEnumSliceFlag(allowed ...string) *EnumSliceFlag
- func NewEnumSliceFlagWithAllAllowed(allowed ...string) *EnumSliceFlag
- func NewEnumSliceFlagWithAllAllowedAndFunc(cmd *cobra.Command, allowedFunc AllowedFunc, defaultvalues ...string) *EnumSliceFlag
- func NewEnumSliceFlagWithFunc(cmd *cobra.Command, allowedFunc AllowedFunc, defaultvalues ...string) *EnumSliceFlag
- func (flag *EnumSliceFlag) Append(value string) error
- func (flag EnumSliceFlag) CompletionFunc(flagName string) (string, ...)
- func (flag EnumSliceFlag) GetSlice() []string
- func (flag *EnumSliceFlag) Replace(values []string) error
- func (flag *EnumSliceFlag) Set(value string) (err error)
- func (flag EnumSliceFlag) String() string
- func (flag EnumSliceFlag) Type() string
Constants ¶
This section is empty.
Variables ¶
var (
InvalidEnumValue = errors.NewSentinel(http.StatusBadRequest, "error.value.invalid", "Flag value \"%s\" is invalid. Expected values are %s")
)
var VERSION = "0.5.0"
VERSION is the version of this package
Functions ¶
This section is empty.
Types ¶
type AllowedFunc ¶ added in v0.3.0
type AllowedFunc func(ctx context.Context, cmd *cobra.Command, args []string, toComplete string) ([]string, error)
AllowedFunc is a function that returns the allowed values for a flag
See https://pkg.go.dev/github.com/spf13/cobra@v1.8.1#Command.RegisterFlagCompletionFunc
type EnumFlag ¶
type EnumFlag struct {
Allowed []string
AllowedFunc AllowedFunc
Value string
// contains filtered or unexported fields
}
EnumFlag represents a flag that can only have a value from a list of allowed values
If the AllowedFunc is set, the Allowed values are ignored and the function is called to get the allowed values.
func NewEnumFlag ¶
NewEnumFlag creates a new EnumFlag
The default value is prepended with a +.
If no default value is provided, the flag will not have a default value.
If more than one default value is provided, the first one is used.
Example:
flag := flags.NewEnumFlag("one", "+two", "three")
func NewEnumFlagWithFunc ¶
func NewEnumFlagWithFunc(cmd *cobra.Command, defaultValue string, allowedFunc AllowedFunc) *EnumFlag
NewEnumFlagWithFunc creates a new EnumFlag with a function to get the allowed values
func (*EnumFlag) CompletionFunc ¶
func (flag *EnumFlag) CompletionFunc(flagName string) (string, func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective))
CompletionFunc returns the completion function of the flag
func (*EnumFlag) Set ¶
Set sets the flag value
If the AllowedFunc is set, the Allowed values are ignored and the function is called to get the allowed values.
implements pflag.Value
type EnumSliceFlag ¶
type EnumSliceFlag struct {
Allowed []string
Values []string
Default []string
AllowedFunc AllowedFunc
AllAllowed bool
// contains filtered or unexported fields
}
EnumSliceFlag represents a flag that can only have values from a list of allowed values
The flag can be repeated to have multiple values.
func NewEnumSliceFlag ¶
func NewEnumSliceFlag(allowed ...string) *EnumSliceFlag
NewEnumSliceFlag creates a new EnumSliceFlag
The default values are prepended with a +.
If no default value is provided, the flag will not have a default value.
Example:
flag := flags.NewEnumSliceFlag("+one", "+two", "three")
func NewEnumSliceFlagWithAllAllowed ¶
func NewEnumSliceFlagWithAllAllowed(allowed ...string) *EnumSliceFlag
NewEnumSliceFlagWithAllAllowed creates a new EnumSliceFlag
The default values are prepended with a +.
If the flag is set to "all", all the allowed values are set.
If no default value is provided, the flag will not have a default value.
Example:
flag := flags.NewEnumSliceFlagWithAllAllowed("+one", "+two", "three")
func NewEnumSliceFlagWithAllAllowedAndFunc ¶ added in v0.2.0
func NewEnumSliceFlagWithAllAllowedAndFunc(cmd *cobra.Command, allowedFunc AllowedFunc, defaultvalues ...string) *EnumSliceFlag
NewEnumSliceFlagWithAllAllowedAndFunc creates a new EnumSliceFlag
func NewEnumSliceFlagWithFunc ¶ added in v0.2.0
func NewEnumSliceFlagWithFunc(cmd *cobra.Command, allowedFunc AllowedFunc, defaultvalues ...string) *EnumSliceFlag
NewEnumSliceFlagWithFunc creates a new EnumSliceFlag
func (*EnumSliceFlag) Append ¶ added in v0.3.2
func (flag *EnumSliceFlag) Append(value string) error
Append appends a value to the flag
implements pflag.SliceValue
func (EnumSliceFlag) CompletionFunc ¶
func (flag EnumSliceFlag) CompletionFunc(flagName string) (string, func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective))
CompletionFunc returns the completion function of the flag
This function is used by the cobra.Command when it needs to complete the flag value.
See: https://pkg.go.dev/github.com/spf13/cobra#Command.RegisterFlagCompletionFunc
func (EnumSliceFlag) GetSlice ¶ added in v0.3.2
func (flag EnumSliceFlag) GetSlice() []string
GetSlice returns the flag value list as a slice of strings
implements pflag.SliceValue
func (*EnumSliceFlag) Replace ¶ added in v0.3.2
func (flag *EnumSliceFlag) Replace(values []string) error
Replace replaces the flag values with the given values
implements pflag.SliceValue
func (*EnumSliceFlag) Set ¶
func (flag *EnumSliceFlag) Set(value string) (err error)
Set sets the flag value
implements pflag.Value
func (EnumSliceFlag) String ¶
func (flag EnumSliceFlag) String() string
String returns the string representation of the flag
implements fmt.Stringer and pflag.Value
func (EnumSliceFlag) Type ¶
func (flag EnumSliceFlag) Type() string
Type returns the type of the flag
implements pflag.Value