Documentation ¶
Overview ¶
Package config contains the configuration handling for dsak.
Index ¶
- func GetFromCommandContext(cmd *cobra.Command) *viper.Viper
- func New(args []string) (*viper.Viper, error)
- func RegisterValue(name string, valueType ValueType, opts ...ValueOption)
- func SetCommandContext(cmd *cobra.Command, config *viper.Viper)
- func Write(cfg *viper.Viper) error
- type SetterFunc
- type StringerFunc
- type Value
- type ValueOption
- func DefaultValue(v interface{}) ValueOption
- func Description(description string) ValueOption
- func Flag(flag string) ValueOption
- func FlagIsPersistent() ValueOption
- func IgnoreEnv() ValueOption
- func Setter(f SetterFunc) ValueOption
- func ShortFlag(flag byte) ValueOption
- func Stringer(f StringerFunc) ValueOption
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFromCommandContext ¶
GetFromCommandContext gets the configuration from a command context. If no configuration is found, a new configuration is created.
func RegisterValue ¶
func RegisterValue(name string, valueType ValueType, opts ...ValueOption)
RegisterValue registers a configuration value. `name` is the global name of the configuration value, must be unique. `valueType` is the type of this configuration value. Configurations are taken in this order : 1. command line flag 2. configuration file 3. environment variable. Names must be composed of words of lowercase letters separated by period. Examples : "timeout", "global.verbose" RegisterValue should be called in the init() function of each command.
func SetCommandContext ¶
SetCommandContext sets the command context to contain a new configuration.
Types ¶
type SetterFunc ¶
SetterFunc is a function that sets the value from a given string.
type StringerFunc ¶
StringerFunc is a function that returns a string representing the value.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents a configuration value.
func (Value) AsRawString ¶
AsRawString gets the configuration value as a raw string, no decorator or quotes.
type ValueOption ¶
ValueOption is a function that can be used to configure a configuration value.
func DefaultValue ¶
func DefaultValue(v interface{}) ValueOption
DefaultValue sets the default value for this configuration value.
func Description ¶
func Description(description string) ValueOption
Description sets configuration description.
func Flag ¶
func Flag(flag string) ValueOption
Flag indicates that this configuration value is controlled by a flag.
func FlagIsPersistent ¶
func FlagIsPersistent() ValueOption
FlagIsPersistant indicates that this configuration is controlled by flag that is persistent in subcommands.
func IgnoreEnv ¶
func IgnoreEnv() ValueOption
IgnoreEnv indicates that this configuration is not controlled by an environment variable.
func Setter ¶
func Setter(f SetterFunc) ValueOption
Setter sets a function to be used when setting value from dsak instead of default func.
func ShortFlag ¶
func ShortFlag(flag byte) ValueOption
ShortFlag indicates that this configuration value is controlled by a short flag.
func Stringer ¶
func Stringer(f StringerFunc) ValueOption
Stringer sets a function to be used when value should be represented as string instead of using fmt.Sprintf("%v").
type ValueType ¶
type ValueType uint16
ValueType is the type of a configuration value.
const ( // ValueTypeString represents a string. ValueTypeString ValueType = iota + 1 // ValueTypeStrings represents a string slice. ValueTypeStrings // ValueTypeUint represents an unsigned integer value, on 64 bits. ValueTypeUint // ValueTypeBool represents a boolean value. ValueTypeBool // ValueTypeStringsMap represents a map[string][]string. ValueTypeStringsMap )