Documentation
¶
Index ¶
- type Config
- type ConfigState
- func (st *ConfigState[Values]) CLI() *cli.FlagSet
- func (st *ConfigState[Values]) Config(fn func(*Values))
- func (st *ConfigState[Values]) Env() *env.FlagSet
- func (st *ConfigState[Values]) ParseCLI(args []string) (unknown []string, err error)
- func (st *ConfigState[Values]) ParseCLIStrict(args []string) error
- func (st *ConfigState[Values]) ParseEnv(env []string) error
- func (st *ConfigState[Values]) ReadFile(path string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// FlagsCLI allows specifying extra CLI flags ontop of those
// generated from your values type. These will be returned to
// you with raw string values from .ParseCLI(). An example use
// case here is setting config file location, usage printing, etc.
CLI cli.FlagSet
// FlagsEnv allows specifying extra env flags ontop of those
// generated from your values type. These will be returned to
// you with raw string value from .ParseEnv(). An example use
// case here is setting config file location.
Env env.FlagSet
// DecodeFile allows specifying a custom file decoder, where 'dst' interface{}
// is your configuration values object and src is the file opened from path
// passed to ConfigState.ReadFile().
//
// If nil the default of env.FileDecoder(...) will be used.
DecodeFile func(dst interface{}, src *os.File) error
}
type ConfigState ¶
type ConfigState[Values any] struct { // contains filtered or unexported fields }
func New ¶
func New[Values any](cfg Config) *ConfigState[Values]
func (*ConfigState[Values]) CLI ¶
func (st *ConfigState[Values]) CLI() *cli.FlagSet
CLI provides access to the ConfigState's underlying cli.FlagSet. NOT CONCURRENCY SAFE.
func (*ConfigState[Values]) Config ¶
func (st *ConfigState[Values]) Config(fn func(*Values))
Config provides safe access to ConfigState's config values.
func (*ConfigState[Values]) Env ¶
func (st *ConfigState[Values]) Env() *env.FlagSet
Env provides access to the ConfigState's underlying env.FlagSet. NOT CONCURRENCY SAFE.
func (*ConfigState[Values]) ParseCLI ¶
func (st *ConfigState[Values]) ParseCLI(args []string) (unknown []string, err error)
ParseCLI will parse CLI arguments and safely load them into the ConfigState's config values, returning unrecognized arguments.
func (*ConfigState[Values]) ParseCLIStrict ¶
func (st *ConfigState[Values]) ParseCLIStrict(args []string) error
ParseCLIStrict will perform .ParseCLI() but return error in the case that unknown arguments are returned.
func (*ConfigState[Values]) ParseEnv ¶
func (st *ConfigState[Values]) ParseEnv(env []string) error
ParseEnv will parse environment variables and safely load them into the ConfigState's config values.
func (*ConfigState[Values]) ReadFile ¶
func (st *ConfigState[Values]) ReadFile(path string) error
ReadFile will parse file at given path and safely load variables into ConfigState's config values.