Documentation
¶
Index ¶
- Variables
- type Provider
- func (p *Provider) BindEnvVar(configName string, envVarName string)
- func (p *Provider) BindPFlag(configName string, flag *pflag.Flag)
- func (p *Provider) GetBool(configName string) (bool, bool)
- func (p *Provider) GetFloat32(configName string) (float32, bool)
- func (p *Provider) GetFloat64(configName string) (float64, bool)
- func (p *Provider) GetInt32(configName string) (int32, bool)
- func (p *Provider) GetInt64(configName string) (int64, bool)
- func (p *Provider) GetString(configName string) (string, bool)
- func (p *Provider) GetUint32(configName string) (uint32, bool)
- func (p *Provider) GetUint64(configName string) (uint64, bool)
- func (p *Provider) LoadConfigFile(configFilePath string) error
- func (p *Provider) SetDefault(configName, value string)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedConfigFileFormat is returned when the config file format // is not supported by the provider. ErrUnsupportedConfigFileFormat = errors.New("unsupported config file format, only yaml, json and toml are supported") )
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is a simple config provider for the CLI that can fall back to a config file or environment variables. This is an alternative approach to using the viper library that was a pain to integrate with cobra in providing config file and env var defaults across multiple levels of subcommands.
The precendence of config values is as follows: 1. Flags 2. Environment variables 3. Config file 4. Flag defaults 5. Config provider defaults
Provider only supports strings, booleans, integers and floats as configuration values. Complex types such as arrays, structs and maps are not supported.
YAML, JSON and TOML are supported as config file formats.
func NewProvider ¶
func NewProvider() *Provider
NewProvider creates a new Provider of configuration values for the CLI.
func (*Provider) BindEnvVar ¶
func (*Provider) GetString ¶
GetString returns the value of a configuration value as a string. It also returns a boolean indicating whether the value was set by the user or if it's a default value. `true` means the value is a default value.