value

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DictValue added in v0.0.18

type DictValue interface {
	Value

	// DefaultStringMap returns the default underlying value for the map
	DefaultStringMap() map[string]string

	// StringMap returns what's in the map currently
	StringMap() map[string]string
}

type EmptyConstructor

type EmptyConstructor func() (Value, error)

EmptyConstructur just builds a new value. Useful to create new values as well as initialize them

type ErrInvalidChoice added in v0.0.16

type ErrInvalidChoice[T comparable] struct {
	Choices []T
}

func (ErrInvalidChoice[T]) Error added in v0.0.16

func (e ErrInvalidChoice[T]) Error() string

type ScalarValue added in v0.0.18

type ScalarValue interface {
	Value

	// DefaultString returns the default underlying value (represented as a string)
	DefaultString() string

	// String returns a string ready to be printed!
	String() string
}

type SliceValue added in v0.0.18

type SliceValue interface {
	Value

	// DefaultStringSlice returns the default underlying value for slice values and nil for others
	DefaultStringSlice() []string

	// StringSlice returns a []string ready to be printed for slice values and nil for others
	StringSlice() []string

	// AppendFromInterface updates a container type Value from an interface (useful for configs)
	// and replaces scalar values (for scalar values, AppendFromInterface is the same as ReplaceFromInterface).
	// Note that AppendFromInterface must be called with the "contained" type for container type Values
	// For example, the StringSlice.AppendFromInterface
	// must be called with a string, not a []string
	// It returns ErrIncompatibleInterface if the interface can't be decoded
	AppendFromInterface(interface{}) error
}

type Value

type Value interface {

	// Choices for this value to contain (represented as strings)
	Choices() []string

	// Description of the type. Useful for help messages. Not guaranteed to be unique. 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{}

	// HasDefault returns true if this value has a default
	HasDefault() bool

	// ReplaceFromInterface replaces a value with one found in an interface.
	// Useful to update a Value from a config.
	ReplaceFromInterface(interface{}) error

	// Update appends to container type Values from a string (useful for CLI flags, env vars, default values)
	// and replaces scalar Values
	Update(string) error

	// ReplaceFromDefault updates the Value from a pre-set default, if one exists. use HasDefault to check whether a default exists
	ReplaceFromDefault()
}

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, ...).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL