Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIncompatibleInterface = errors.New("could not decode interface into Value")
Functions ¶
This section is empty.
Types ¶
type EmptyConstructor ¶
EmptyConstructur just builds a new value. Useful to create new values as well as initialize them
func StringEnum ¶ added in v0.0.3
func StringEnum(choices ...string) EmptyConstructor
StringEnum acts just like a string, except it only lets the user update from the choices provided when creating the EmptyConstructor for it.
type Value ¶
type Value interface { // Description of the type. useful for help messages. Should not be used as an ID. Description() string // Get returns the underlying value. It's meant to be type asserted against // Example: myInt := v.(int) Get() interface{} // ReplaceFromInterface replaces a value with one found in an interface. // Useful to update a Value from a config. ReplaceFromInterface(interface{}) error // String returns a string ready to be printed! String() string // StringSlice returns a []string ready to be printed for slice values and nil for others StringSlice() []string // TypeInfo specifies whether what "overall" type of value this is - scalar, slice, etc. TypeInfo() TypeInfo // Update appends to container type Values from a string (useful for CLI flags, env vars, default values) // and replaces scalar Values Update(string) error // UpdateFromInterface updates a container type Value from an interface (useful for configs) // and replaces scalar values (for scalar values, UpdateFromInterface is the same as ReplaceFromInterface). // Note that UpdateFromInterface must be called with the "contained" type for container type Values // For example, the StringSlice.UpdateFromInterface // must be called with a string, not a []string // It returns ErrIncompatibleInterface if the interface can't be decoded UpdateFromInterface(interface{}) error }
Value is a "generic" type to store different types into flags Inspired by https://golang.org/src/flag/flag.go . There are two underlying "type" families designed to fit in Value: scalar types (Int, String, ...) and container types (IntSlice, StringMap, ...).
func Duration ¶ added in v0.0.6
Duration is updateable from a string parsed with https://pkg.go.dev/time#ParseDuration
func Int ¶
Int is updateable from a float or int. If a float is passed, it will be truncated. Example: 4.5 -> 4, 3.99 -> 3
func IntSlice ¶
IntSlice is updateable from a float or int. If a float is passed, it will be truncated. Example: 4.5 -> 4, 3.99 -> 3
func StringSlice ¶
StringSlice accepts a string from a user and adds it to a slice. Pretty self explanatory.