Documentation
¶
Overview ¶
Package gflag exposes generic types to deal with flags.
the new types can be readily used as extensions to the github.com/spf13/flag package.
Most of the current pflag functionality can be obtained from gflag using generic types.
There are a few exceptions though: * []byte semantics as base64-encoded string is not available yet (will be, as part of the extensions package). * int semantics a increment/decrement count is not avaiable directly (it is available in the extensions package) * map semantics (StringToXXX family of pflag types) are not supported yet.
Index ¶
- type FlaggablePrimitives
- type FlaggableTypes
- type SliceValue
- func (m *SliceValue[T]) Append(strValue string) error
- func (m *SliceValue[T]) GetSlice() []string
- func (m *SliceValue[T]) MarshalFlag() (string, error)
- func (m *SliceValue[T]) Replace(strValues []string) error
- func (m *SliceValue[T]) Set(strValue string) error
- func (m *SliceValue[T]) String() string
- func (m *SliceValue[T]) Type() string
- func (m *SliceValue[T]) UnmarshalFlag(value string) error
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FlaggablePrimitives ¶
type FlaggablePrimitives interface {
constraints.Integer |
constraints.Float |
~string |
~bool |
~[]byte // aka: ~[]uint8 |
}
FlaggablePrimitives is a type constraint that holds all primitive types supported by pflag.
Exception: complex types are not supported.
type FlaggableTypes ¶
FlaggableTypes is a type constraint that holds all types supported by pflag, besides primitive types.
type SliceValue ¶
type SliceValue[T FlaggablePrimitives | FlaggableTypes] struct { Value *[]T // contains filtered or unexported fields }
SliceValue is a generic type that implements github.com/spf13/pflag.Value and SliceValue.
func NewFlagSliceValue ¶
func NewFlagSliceValue[T FlaggablePrimitives | FlaggableTypes](addr *[]T, defaultValue []T) *SliceValue[T]
NewFlagSliceValue constructs a generic flag compatible with github.com/spf13/pflag.SliceValue.
Since the flag type is inferred from the underlying data type, some flexibility allowed by pflag is not always possible at this point.
For example, when T = []string, NewFlagSliceValue adopts the semantics of the pflag.StringSlice (with comma-separated values), whereas pflag also supports a StringArray flag.
func (*SliceValue[T]) Append ¶
func (m *SliceValue[T]) Append(strValue string) error
Append a single element to the SliceValue, from its string representation.
func (*SliceValue[T]) GetSlice ¶
func (m *SliceValue[T]) GetSlice() []string
GetSlice return a []string representation of the slice values.
func (*SliceValue[T]) MarshalFlag ¶
func (m *SliceValue[T]) MarshalFlag() (string, error)
MarshalFlag implements go-flags Marshaller interface
func (*SliceValue[T]) Replace ¶
func (m *SliceValue[T]) Replace(strValues []string) error
func (*SliceValue[T]) Set ¶
func (m *SliceValue[T]) Set(strValue string) error
Set knows how to config a string representation of the Value into a type T.
func (*SliceValue[T]) String ¶
func (m *SliceValue[T]) String() string
func (*SliceValue[T]) Type ¶
func (m *SliceValue[T]) Type() string
func (*SliceValue[T]) UnmarshalFlag ¶
func (m *SliceValue[T]) UnmarshalFlag(value string) error
UnmarshalFlag implements go-flags Unmarshaller interface
type Value ¶
type Value[T FlaggablePrimitives | FlaggableTypes] struct { Value *T NoOptDefVal string }
Value is a generic type that implements github.com/spf13/pflag.Value.
func NewFlagValue ¶
func NewFlagValue[T FlaggablePrimitives | FlaggableTypes](addr *T, defaultValue T) *Value[T]
NewFlagValue constructs a generic flag compatible with github.com/spf13/pflag.Value.
Since the flag type is inferred from the underlying data type, some flexibility allowed by pflag is not always possible at this point.
For example, when T = []byte, NewFlagValue adopts the semantics of the pflag.BytesHex flag, whereas pflag aslo supports a BytesBase64 flag.
Similarly, when T = int, we adopt the semantics of pflag.Int and not pflag.Count.
func (*Value[T]) MarshalFlag ¶
MarshalFlag implements go-flags Marshaller interface
func (*Value[T]) UnmarshalFlag ¶
UnmarshalFlag implements go-flags Unmarshaller interface
Directories
¶
| Path | Synopsis |
|---|---|
|
Package extensions provides extensions to the github.com/spf13/pflag package.
|
Package extensions provides extensions to the github.com/spf13/pflag package. |