Documentation ¶
Overview ¶
Package contour: a package for storing settings. These settings may be configuration settings or application settings.
Application settings are either Core or Basic settings. Core settings cannot be modified once Added with AddCore functions. Basic settings are set by Add functions and can be updated with Update functions. These settings are not exposed as configuration file variables, environment variables, or flags. They cannot be modified by any of them.
Configuration settings are settings that are updateable by one or more of the following, depending on what type of configuration setting they are, in order of override precedence: configuration file variable, environment variable, and flag. Configuration settings are registered. They are registered with default values and are overridable according to their configuration setting type. For custom override properties, e.g. can be set by either a configuration file or a flag but not by an environment variable, use the Register function.
Registering a configuration setting will result in settings being configured to use that setting type's source, along with any lower precedence sources during the Set process, e.g. registering a ConfFileVar will result in settings being configured to use a configuration file and registering a Flag will result in settings being configured to use a configuration file and check environment variables.
After registration, settings can be set to ignore certain configuration sources using the SetUseConfFile and SetUseEnvVars methods. Flag parsing is always explicitly done by the caller with the ParseFlags method.
The configuration file can be explicitly set, in which case the configuration file format will be inferred from the extension with unknown extensions resulting in an UnsupportedFormatError. If there are configuration settings registered, of any type, and the configuration file has not been set, it will be assumed to be SettingsName.Format where SettingsName is the name of the settings and Format is the configuration file format that settings is set to use, which defaults to JSON. The format can be set using the SetFormat method. This only needs to be done if the configuration file is not explictly set using the SetConfFilename method. The supported configuration formats are: JSON, TOML, and YAML. A settings can also be configured to search for the configuration file until it is found. Where it looks depends on how it has been configured and what additional information the settings has been provided:
configuration filename paths set with SetConfFilePaths paths extracted from env vars set by SetConfFilePathEnvVars* working directory executable directory paths extracted from the PATH* * the env vars may contain multiple paths; each path will be checked
By default, a missing configuration file results in an os.PathError with a list of all paths that were checked along with an os.IsNotExist error. A settings can be set to not return an error when the configuration file cannot be found by using the SetErrOnMissingConfFile method.
Contour only saves the top level keys of configuration files as settings. For configuration file settings that are arrays, maps, or objects, their values will be saved as an interface{}.
Environment variables are UPPER CASE and use a NAME_KEY as the variable name, where NAME is the name of the Settings, the executable name for the package global Settings, and KEY is the name, or key, of the setting.
Flags can be registered with either a short flag or alias using the short parameter of Register Flag functions.
All operations are thread-safe.
The workflow for application configurations is:
Register all configuration settings. Call the Set() function. Call the ParseFlags() function.
Non-configuration application settings, Core and Basic, can be added at anytime.
For convenience, there's a predefined 'standard' Settings, whose name is the executable's name.
Index ¶
- Variables
- func AddBool(k string, v bool) error
- func AddBoolCore(k string, v bool) error
- func AddInt(k string, v int) error
- func AddInt64(k string, v int64) error
- func AddInt64Core(k string, v int64) error
- func AddIntCore(k string, v int) error
- func AddInterface(k string, v interface{}) error
- func AddInterfaceCore(k string, v interface{}) error
- func AddString(k, v string) error
- func AddStringCore(k, v string) error
- func Bool(k string) bool
- func BoolE(k string) (bool, error)
- func CheckExeDir() bool
- func CheckWD() bool
- func ConfFilePathEnvVars() []string
- func ConfFilePaths() []string
- func ConfFilename() string
- func EnvVarName(k string) string
- func ErrOnMissingConfFile() bool
- func Exists(k string) bool
- func Get(k string) interface{}
- func GetE(k string) (interface{}, error)
- func GetEnvVarPaths(key string) []string
- func GetFormatString() string
- func Int(k string) int
- func Int64(k string) int64
- func Int64E(k string) (int64, error)
- func IntE(k string) (int, error)
- func Interface(k string) interface{}
- func InterfaceE(k string) (interface{}, error)
- func IsConfFileVar(k string) bool
- func IsConfFileVarE(k string) (bool, error)
- func IsCore(k string) bool
- func IsCoreE(k string) (bool, error)
- func IsEnvVar(k string) bool
- func IsEnvVarE(k string) (bool, error)
- func IsFlag(k string) bool
- func IsFlagE(k string) (bool, error)
- func IsSet() bool
- func Name() string
- func ParseFlags() ([]string, error)
- func PathsFromEnvVar(s string) []string
- func RegisterBoolConfFileVar(k string, v bool) error
- func RegisterBoolEnvVar(k string, v bool) error
- func RegisterBoolFlag(k, short string, v bool, dflt, usage string) error
- func RegisterInt64ConfFileVar(k string, v int64) error
- func RegisterInt64EnvVar(k string, v int64) error
- func RegisterInt64Flag(k, short string, v int64, dflt, usage string) error
- func RegisterIntConfFileVar(k string, v int) error
- func RegisterIntEnvVar(k string, v int) error
- func RegisterIntFlag(k, short string, v int, dflt, usage string) error
- func RegisterInterfaceConfFileVar(k string, v interface{}) error
- func RegisterSetting(typ, name, short string, value interface{}, dflt, usage string, ...) error
- func RegisterStringConfFileVar(k, v string) error
- func RegisterStringEnvVar(k, v string) error
- func RegisterStringFlag(k, short, v, dflt, usage string) error
- func SearchPATH() bool
- func Set() error
- func SetCheckExeDir(b bool)
- func SetCheckWD(b bool)
- func SetConfFilePathEnvVars(envVars []string)
- func SetConfFilePaths(paths []string)
- func SetConfFilename(v string)
- func SetErrOnMissingConfFile(b bool)
- func SetFormat(f Format)
- func SetFormatString(v string) error
- func SetFromConfFile() error
- func SetFromEnvVars() error
- func SetSearchPATH(b bool)
- func SetUsage(f func())
- func String(k string) string
- func StringE(k string) (string, error)
- func UpdateBool(k string, v bool) error
- func UpdateInt(k string, v int) error
- func UpdateInt64(k string, v int64) error
- func UpdateInterface(k string, v interface{}) error
- func UpdateString(k string, v string) error
- func UseConfFile() bool
- func UseEnvVars() bool
- func UseFlags() bool
- func Visited() []string
- func WasVisited(k string) bool
- type CoreUpdateError
- type DataTypeError
- type Format
- type SettingExistsError
- type SettingNotFoundError
- type SettingType
- type Settings
- func (s *Settings) AddBool(k string, v bool) error
- func (s *Settings) AddBoolCore(k string, v bool) error
- func (s *Settings) AddInt(k string, v int) error
- func (s *Settings) AddInt64(k string, v int64) error
- func (s *Settings) AddInt64Core(k string, v int64) error
- func (s *Settings) AddIntCore(k string, v int) error
- func (s *Settings) AddInterface(k string, v interface{}) error
- func (s *Settings) AddInterfaceCore(k string, v interface{}) error
- func (s *Settings) AddString(k, v string) error
- func (s *Settings) AddStringCore(k, v string) error
- func (s *Settings) Bool(k string) bool
- func (s *Settings) BoolE(k string) (bool, error)
- func (s *Settings) CheckExeDir() bool
- func (s *Settings) CheckWD() bool
- func (s *Settings) ConfFilePathEnvVars() []string
- func (s *Settings) ConfFilePaths() []string
- func (s *Settings) ConfFilename() string
- func (s *Settings) EnvVarName(k string) string
- func (s *Settings) ErrOnMissingConfFile() bool
- func (s *Settings) Exists(k string) bool
- func (s *Settings) Get(k string) interface{}
- func (s *Settings) GetE(k string) (interface{}, error)
- func (s *Settings) GetFormat() Format
- func (s *Settings) GetFormatString() string
- func (s *Settings) Int(k string) int
- func (s *Settings) Int64(k string) int64
- func (s *Settings) Int64E(k string) (int64, error)
- func (s *Settings) IntE(k string) (int, error)
- func (s *Settings) Interface(k string) interface{}
- func (s *Settings) InterfaceE(k string) (interface{}, error)
- func (s *Settings) IsConfFileVar(k string) bool
- func (s *Settings) IsConfFileVarE(k string) (bool, error)
- func (s *Settings) IsCore(k string) bool
- func (s *Settings) IsCoreE(k string) (bool, error)
- func (s *Settings) IsEnvVar(k string) bool
- func (s *Settings) IsEnvVarE(k string) (bool, error)
- func (s *Settings) IsFlag(k string) bool
- func (s *Settings) IsFlagE(k string) (bool, error)
- func (s *Settings) IsSet() bool
- func (s *Settings) Name() string
- func (s *Settings) ParseFlags(args []string) ([]string, error)
- func (s *Settings) RegisterBoolConfFileVar(k string, v bool) error
- func (s *Settings) RegisterBoolEnvVar(k string, v bool) error
- func (s *Settings) RegisterBoolFlag(k, short string, v bool, dflt, usage string) error
- func (s *Settings) RegisterInt64ConfFileVar(k string, v int64) error
- func (s *Settings) RegisterInt64EnvVar(k string, v int64) error
- func (s *Settings) RegisterInt64Flag(k, short string, v int64, dflt, usage string) error
- func (s *Settings) RegisterIntConfFileVar(k string, v int) error
- func (s *Settings) RegisterIntEnvVar(k string, v int) error
- func (s *Settings) RegisterIntFlag(k, short string, v int, dflt, usage string) error
- func (s *Settings) RegisterInterfaceConfFileVar(k string, v interface{}) error
- func (s *Settings) RegisterSetting(typ, name, short string, value interface{}, dflt, usage string, ...) error
- func (s *Settings) RegisterStringConfFileVar(k, v string) error
- func (s *Settings) RegisterStringEnvVar(k, v string) error
- func (s *Settings) RegisterStringFlag(k, short, v, dflt, usage string) error
- func (s *Settings) SearchPATH() bool
- func (s *Settings) Set() error
- func (s *Settings) SetCheckExeDir(b bool)
- func (s *Settings) SetCheckWD(b bool)
- func (s *Settings) SetConfFilePathEnvVars(envVars []string)
- func (s *Settings) SetConfFilePaths(paths []string)
- func (s *Settings) SetConfFilename(v string) error
- func (s *Settings) SetErrOnMissingConfFile(b bool)
- func (s *Settings) SetFormat(f Format)
- func (s *Settings) SetFormatString(v string) error
- func (s *Settings) SetFromConfFile() error
- func (s *Settings) SetFromEnvVars() error
- func (s *Settings) SetSearchPATH(b bool)
- func (s *Settings) SetUsage(f func())
- func (s *Settings) String(k string) string
- func (s *Settings) StringE(k string) (string, error)
- func (s *Settings) UpdateBool(k string, v bool) error
- func (s *Settings) UpdateInt(k string, v int) error
- func (s *Settings) UpdateInt64(k string, v int64) error
- func (s *Settings) UpdateInterface(k string, v interface{}) error
- func (s *Settings) UpdateString(k, v string) error
- func (s *Settings) UseConfFile() bool
- func (s *Settings) UseEnvVars() bool
- func (s *Settings) UseFlags() bool
- func (s *Settings) Visited() []string
- func (s *Settings) WasVisited(k string) bool
- type ShortFlagExistsError
- type UnsupportedFormatError
- type UpdateError
Constants ¶
This section is empty.
Variables ¶
var ( ErrFlagsParsed = errors.New("flags have already been parsed") ErrUseFlagsFalse = errors.New("not set to use flags") )
var ErrNoSettingName = errors.New("no setting name provided")
var (
Exe = appname.Get() // Exe is the name of the running executable.
)
Functions ¶
func AddBool ¶
AddBool adds a bool setting to the standard settings with the key k and value f. This can be only be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func AddBoolCore ¶
AddBoolCore adds a Core bool setting to the standard settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func AddInt ¶
AddInt adds an int setting to the standard settings with the key k and value f. This can be only be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func AddInt64 ¶
AddInt64 adds an int64 setting to the standard settings with the key k and value f. This can be only updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func AddInt64Core ¶
AddInt64Core adds a Core int64 setting to the standard settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func AddIntCore ¶
AddIntCore adds a Core int setting to the standard settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func AddInterface ¶
AddInterface adds an interface setting to the standard settings with the key k and value f. This can be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func AddInterfaceCore ¶
AddInterfaceCore adds a Core interface setting to the standard settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func AddString ¶
AddString adds a string setting to the standard settings with the key k and value f. This can be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func AddStringCore ¶
AddStringCore adds a Core string setting to the standard settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func Bool ¶
Bool returns the standard settings' value for k as a bool. A false will be returned if k doesn't exist or if its value is not a bool.
func BoolE ¶
BoolE returns the standard settings' value for k as a bool. A vSettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is not bool.
func CheckExeDir ¶
func CheckExeDir() bool
CheckExeDir returns if Settings should check the executable directory for the configuration file.
func CheckWD ¶
func CheckWD() bool
CheckWD returns if settings should check the working directory for the configuration file.
func ConfFilePathEnvVars ¶
func ConfFilePathEnvVars() []string
ConfFilePathEnvVars returns the names of the environment variables that have paths that the standard settings should check when looking for the configuration file.
func ConfFilePaths ¶
func ConfFilePaths() []string
ConfFilePaths returns the paths that the standard settings should check when looking for the configuration file.
func ConfFilename ¶
func ConfFilename() string
ConfFilename returns the standard settings' configuration filename.
func EnvVarName ¶
EnvVarName returns the environment variable name for k. This will be NAME_K, where K is k and NAME is the standard settings' name (executable name).
func ErrOnMissingConfFile ¶
func ErrOnMissingConfFile() bool
ErrOnMissingConfFile returns if the standard settings is configured to return an error if the configuration file cannot be located.
func Exists ¶
Exists returns if setting k exists. A false will be be returned if k doesn't exist in the standard settings.
func Get ¶
func Get(k string) interface{}
Get returns the standard settings' value for k as an interface{}. A nil is returned if k doesn't exist.
func GetE ¶
GetE returns the standard settings' value for k as an interface{}. A SettingNotFoundError is returned if k doesn't exist.
func GetEnvVarPaths ¶
GetEnvVarPaths gets the value of an environment variable, that is assumed to have path info, splits it into its path elements, and expands them, returning a list of paths.
If key is empty, a nil is returned. If the environment variable for the key is either not set or is empty, an empty slice will be returned.
func GetFormatString ¶
func GetFormatString() string
GetFormatString returns the standard settings' format to use if the ConfFilename hasn't been explicitly set as a string
func Int ¶
Int returns the standard settings' value for k as an int. A 0 will be returned if k doesn't exist or if its value is not an int.
func Int64 ¶
Int64 returns the standard settings' value for k as an int64. A 0 will be returned if k doesn't exist or if its value is neither an int64 nor an int setting.
func Int64E ¶
Int64E returns the standard settings' value for k as an int64. A SettingNotFoundError is returned if k doesn't exist in. A DataTypeError will be returned if the value is neither an int64 nor an int.
func IntE ¶
IntE returns the standard settings' value for k as an int. A SettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is not an int.
func Interface ¶
func Interface(k string) interface{}
Interface returns the standard settings' value for k as an interface{}. A nil will be returned if k doesn't exist.
func InterfaceE ¶
InterfaceE returns the standard settings' value for k as an interface{}. A SettingNotFoundError is returned if k doesn't exist.
func IsConfFileVar ¶
IsConfFileVar returns if setting k is a ConfFileVar setting. A false will be returned if k doesn't exist in the standard settings.
func IsConfFileVarE ¶
IsConfFileVarE returns if setting k is a ConfFileVar setting. A SettingNotFoundErr will be returned if k doesn't exist in the standard settings.
func IsCore ¶
IsCore returns if setting k is a Core setting. False will be returned if k doesn't exist in settings.
func IsCoreE ¶
IsCoreE returns if setting k is a Core setting. A SettingNotFoundErr will be returned if k doesn't exist in the standard settings.
func IsEnvVar ¶
IsEnvVar returns if setting k is an EnvVar setting. A false will be returned if k doesn't exist in the standard settings.
func IsEnvVarE ¶
IsEnvVarE returns if setting k is an EnvVar setting. A SettingNotFoundErr will be returned if k doesn't exist in the standard settings.
func IsFlag ¶
IsFlag returns if setting k is a Flag setting. A false will be returned if k doesn't exist in the standard settings.
func IsFlagE ¶
IsFlagE returns if setting k is a Flag setting. A SettingNotFoundErr will be returned if k doesn't exist in the standard settings.
func IsSet ¶
func IsSet() bool
IsSet returns if the standard settings' configuration settings have been set from all of its configured sources.
func ParseFlags ¶
ParseFlags parses the command-line args from os.Args[1:]. Only settings of type Flag can be set via ParseFlags. Flags have the highest precedence. After parsing, any non-flag args are returned to the caller and a list of flags in the args is cached.
If the standard settings has already parsed the flags or standard settings is set to not use flags, nothing will be done and nothing will be returned.
All of standard settings' flags must be registered prior to calling.
func PathsFromEnvVar ¶
PathsFromEnvVars returns a list of expanded paths found in the environemnt variable s. If nothing was found, or the environment variable was empty, a nil will be returned.
func RegisterBoolConfFileVar ¶
RegisterBoolConfFileVar registers a bool setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterBoolEnvVar ¶
RegisterBoolEnvVar registers a bool setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterBoolFlag ¶
RegisterBoolFlag registers a bool setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterInt64ConfFileVar ¶
RegisterInt64ConfFileVar registers an int64 setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterInt64EnvVar ¶
RegisterInt64EnvVar registers an int64 setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterInt64Flag ¶
RegisterInt64Flag registers an int64 setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterIntConfFileVar ¶
RegisterIntConfFileVar registers an int setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterIntEnvVar ¶
RegisterIntEnvVar registers an int setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterIntFlag ¶
RegisterIntFlag registers an int setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterInterfaceConfFileVar ¶
RegisterInterfaceConfFileVar registers an int setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterSetting ¶
func RegisterSetting(typ, name, short string, value interface{}, dflt, usage string, IsCore, IsConfFileVar, IsEnv, IsFlag bool) error
RegisterSetting registers a setting with the standard settings. For most settings, the data and setting type specific registration and add functions should be used. The exception would be when more granular control over what can update a registered setting is needed. This method allows Is[ConfFileVar|EnvVar|Flag] bools to be set independently.
If a setting with the key k already exists, a SettingExistsError will be returned. If k is an empty string an ErrNoSettingName will be returned.
The short, dflt, and usage parms only apply to settings whose IsFlag bool is true.
For non-Core settings, IsCore must be false. If IsCore is true, k's value cannot be changed after registration, regardless of the truthiness of Is[ConfFileVar|IsEnvVar|IsFlag]. For Core settings, AddCore methods should be used.
If the setting can be updated by a configuration file, environment variable or a flag, the Is[ConfFileVar|IsEnv|IsFlag] bools should be set to true as appropriate. These conditionals are independent; e.g. a setting can have both IsConfFileVar and IsFlag set to true if the setting is not to be updateable from an environment variable.
If Is[Core|ConfFileVar|Env|Flag] are all false, the setting will only be updateable by using the Update methods. For these kind of settings, the usage of Add functions should be preferred. These setting will not be exposed to the configuration file, as an environment variable, or as a flag.
For non string, bool, int, and int64 types, the type must be "interface{}"
func RegisterStringConfFileVar ¶
RegisterStringConfFileVar registers a string setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterStringEnvVar ¶
RegisterStringEnvVar registers a string setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func RegisterStringFlag ¶
RegisterStringFlag registers a string setting with the standard settings using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func SearchPATH ¶
func SearchPATH() bool
SearchPATH returns if the standard settings should use the user's PATH environment variable to check for the configuratiom file.
func Set ¶
func Set() error
Set updates the standard settings' configuration from a configuration file and environment variables. This is only run once; subsequent calls will result in no changes. Only settings that are of type ConfFileVar or EnvVar will be affected. This does not handle flags.
Once the standard settings has been set, updated, it will not update again; subsequent calls will result in nothing being done.
All ConfFileVar, EnvVar, and Flag settings must be registered before calling Set.
func SetCheckExeDir ¶
func SetCheckExeDir(b bool)
SetCheckExeDir sets if the standard settings should check the executable directory for the configuration file.
func SetCheckWD ¶
func SetCheckWD(b bool)
SetCheckWD sets if settings should check the working directory for the configuration file.
func SetConfFilePathEnvVars ¶
func SetConfFilePathEnvVars(envVars []string)
SetConfFilePathEnvVars sets the names of the environment variables that have paths that the standard settings should check when looking for the configuration file. The environment variables will be checked in the order provided. The environment variables may contain multiple paths.
func SetConfFilePaths ¶
func SetConfFilePaths(paths []string)
SetConfFilePaths sets the paths that the standard settings should check when looking for the configuration file. The paths will be checked in the order provided.
func SetConfFilename ¶
func SetConfFilename(v string)
SetConfFilename sets the standard settings' configuration filename and configures settings to use a configuration file. If the filename is empty, an error is returned. If the filename's extension isn't parsable to a supported configuration format, an UnsupportedFormatError is returned.
func SetErrOnMissingConfFile ¶
func SetErrOnMissingConfFile(b bool)
SetErrOnMissingConfFile sets if the standard settings should return an error if the confiugration file cannot be located.
func SetFormat ¶
func SetFormat(f Format)
SetFormat sets the standard settings' format to use for the conffile if the ConfFilename hasn't been explicitly set.
func SetFormatString ¶
SetFormatString sets the standard settings' format, using a string, to use for the configuration file if the ConfFilename hasn't been explicitly set. If the string isn't parsable to a supported Format, an UnsupportedFormatError will be returned.
func SetFromConfFile ¶
func SetFromConfFile() error
SetFromConfFile updates the settings' configuration from the configuration file. If the configuration filename was not set using the SetConfFilename method, settings will look for the configuration file using the settings' name and it's format: name.format.
The format, in full, is used as the extension, i.e. JSON's extension will be 'json', TOML's extension will be 'toml', and YAML's extension will be 'yaml'.
Once the settings has been set, updated from the configuration file, they will not be updated again from the configuration file; subsequent calls will result in nothing being done.
The settings will look for the configuration file according to how it's been configured.
filename confFilePaths + filename confFileEnvVars + filename (each env var may have multiple path elements) working directory + filename executable directory + filename $PATH element + filename (PATH may have multiple path elements)
Any of the above elements that are either empty or false are skipped.
If the file cannot be found, an os.PathError with an os.ErrNotExist and a list of all paths checked is returned.
func SetFromEnvVars ¶
func SetFromEnvVars() error
SetFromEnvVars updates the standard settings' configuration from environment variables.
Once the standard settings has been set, updated, from environment variables they, will not be updated again from environment variables; subsequent calls will result in nothing being done.
A setting's env name is a concatonation of the settings' name, an underscore (_), and the setting's key, e.g. given a settings with the name 'foo', a setting whose key is 'bar' will be updateable with the environment variable FOO_BAR.
func SetSearchPATH ¶
func SetSearchPATH(b bool)
SetSearchPATH sets if the standard settings should use the user's PATH environment variable to check for the configuratiom file.
func String ¶
String returns the standard settings' value for k as a string. An empty string, "", will be returned if k doesn't exist or if its value is not a string.
func StringE ¶
StringE returns the standard settings' value for k as a string. A SettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is not a string.
func UpdateBool ¶
UpdateBool updates k with a boo, v. If the standard settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func UpdateInt ¶
UpdateInt updates k with aan int, v. If the standard settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func UpdateInt64 ¶
UpdateInt64 updates k with an int64, v. If the standard settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func UpdateInterface ¶
UpdateInterface updates k with aan int, v. If the standard settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func UpdateString ¶
UpdateString updates a string setting. If the standard setting k doesn't exist, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func UseConfFile ¶
func UseConfFile() bool
UseConfFile returns if the standard settings will update its configuration settings from a configuration file.
func UseEnvVars ¶
func UseEnvVars() bool
UseEnvVars returns if the standard settings will update its configuration settings from environment variables.
func UseFlags ¶
func UseFlags() bool
UseFlags returns if the standard settings has any flags that can be updated by ParseFlags.
func Visited ¶
func Visited() []string
Visited returns the names of all standard settings' flags that were set during flag parsing, in lexical order.
func WasVisited ¶
WasVisited returns if a standard settings flag k was parsed in the processing of args.
Types ¶
type CoreUpdateError ¶
type CoreUpdateError struct {
// contains filtered or unexported fields
}
CoreUpdateError happens when there's an attempt to update a Core setting.
func (CoreUpdateError) Error ¶
func (e CoreUpdateError) Error() string
type DataTypeError ¶
type DataTypeError struct {
// contains filtered or unexported fields
}
DataTypeError occurs when the requested setting's data type is different than the type requested.
func (DataTypeError) Error ¶
func (e DataTypeError) Error() string
type Format ¶
type Format int
Format is the type of esupported encoding for configuration files.
func GetFormat ¶
func GetFormat() Format
GetFormat returns the standard settings' format to use if the ConfFilename hasn't been explicitly set.
func ParseFilenameFormat ¶
ParseFilenameFormat takes a string that represents a filename and returns the files format based on its extension. If the filename either doesn't have an extension or the extension is not one of a supported file format an UnsupportedFormatError will be returned.
func ParseFormat ¶
ParseFormat takes a string and returns the Format it represents or an UnsupportedFormatError if it can't be matched to a supported format. The string is normalized to lower case before matching.
type SettingExistsError ¶
type SettingExistsError struct {
// contains filtered or unexported fields
}
SettingExistsError occurs when a setting being Added or Registered already exists under the same name (k).
func (SettingExistsError) Error ¶
func (e SettingExistsError) Error() string
type SettingNotFoundError ¶
type SettingNotFoundError struct {
// contains filtered or unexported fields
}
SettingNotFoundError occurs when a setting isn't found.
func (SettingNotFoundError) Error ¶
func (e SettingNotFoundError) Error() string
type SettingType ¶
type SettingType int
SettingType is type of setting.
const ( // Basic settings are settings that are none of the below. These are often // referred to as application settings: settings that can only be updated // within an application and not by configuration files, environment // variables, or flags. These settings do not have to be registered. Basic SettingType = iota + 1 // Core settings are immutable once registered. Core // ConFileVar settings can be set from a configuration file. ConfFileVar // EnvVar settings can be set from a configuration file and an environment // variable; unless it has been explicitly set to not be updateable from a // configuration file. EnvVar // Flag settings can be set from a configuration file, an environment // variable, and a flag; unless it has been explicitly set to not be // updateable from either a configuration file or an environment variable. Flag )
These settings are in order of precedence. Each setting type can be set by any of the types with higher precedence if contour is configured to use that type.
func (SettingType) String ¶
func (t SettingType) String() string
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings is a named group of settings and information related to that set.
The name of the Settings is used for environment variable naming, if applicable.
Configuration settings, settings that can be set from a configuration file, an environment variable, or a flag are registered with their default value. Settings will then update them with the anything it finds using the Set and ParseFlags methods. Configuration settings are updated according to the type that the are registered as; with higher precedence types being updatable from a lower precedence source, e.g. a Flag setting can be updated from a configuration file, an environment variable, or a flag, while a ConfFileVar setting can only be updated by a configuration file. The order of precedence is:
ConfFileVar EnvVar Flag
In addition to configuration settings there are settings and Core settings. Core settings cannot be changed once they are set; any attempt to update a core setting will result in an error. Core settings are added using addCore methods. Regular settings cannot be updated by an external source, e.g. a configuration file, an environment variable, or a flag, but can be updated using an Update method.
If the configuration filename was set using the SetConfFilename method or a setting was registered, an attempt will be made to laod setting information from a configuration file. If the configuration filename wasn't explicitly set, settings will build it using it's name and configured format, which defaults to JSON. The extension of the configuration file will be the format, i.i. JSON's extension will be 'json', TOML's extension will be 'toml', and YAML's extension will be 'yaml'.
Settings will look for the configuration file according to the information it has and how it has been configured, e.g. look in additional paths provided to it, look in environment variables for paths, look in the executable directory, search the $PATH, etc. Settings defaults to returning an os.ErrNotExist os.PathError but it can be configured to not return an error if the configuration file is not found. New Settings are configured to search for the confiugration file in the $PATH.
If any configuration settings were registered as a Flag or EnvVar setting, Settings will check the setting's corresponding environment variable. A setting's environment variable is a concatonation of the Settings' name and the setting's key, in UPPER_SNAKE_CASE, e.g. the environmnet variable name for a Settings with the name foo and a setting with the key bar would be FOO_BAR.
Registering a ConfFileVar setting will set settings to look for a configuration file during the set process. Registering either an EnvVar or a Flag will set settings to look for a configuration file during the set process and check environment variables. After registering all configuration settings, the settings can be explicitly set to not use a configuration file or environment variables using the SetUseConfFile and SetUseEnvVars methods.
Once a Settings has been updated from a configuration file and environment variables, configuration settings cannot be updated again from those sources, subsequent attempts will result in no error and nothing being done.
If any configuration settings were registered as a Flag, ParseFlags should be called. Once the flags have been parsed, subsequent calls to ParseFlags will return an ErrFlagsParsed error. If settings is not configured to use flags, ParseFlags will return an ErrUSeFlagsFalse error.
Settings are safe for concurrent use.
func (*Settings) AddBool ¶
AddBool adds a bool setting to the settings with the key k and value f. This can be only be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) AddBoolCore ¶
AddBoolCore adds a Core bool setting to the settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) AddInt ¶
AddInt adds an int setting to the settings with the key k and value f. This can be only be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) AddInt64 ¶
AddInt64 adds an int64 setting to the settings with the key k and value f. This can be only updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) AddInt64Core ¶
AddInt64Core adds a Core int64 setting to the settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) AddIntCore ¶
AddIntCore adds a Core int setting to the settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) AddInterface ¶
AddInterface adds an interface{} setting to the settings with the key k and value v. This can be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) AddInterfaceCore ¶
AddInterfaceCore adds a Core interface{} setting to the settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) AddString ¶
AddString adds a string setting to the settings with the key k and value f. This can be updated using the Update functions. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) AddStringCore ¶
AddStringCore adds a Core string setting to the settings with the key k and value v. The value of this setting cannot be changed once it is added. If a setting with the same name, k, exists, a SettingExistsErr will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) Bool ¶
Bool returns the settings' value for k as a bool. A false will be returned if k either doesn't exist or if its value is not a bool.
func (*Settings) BoolE ¶
BoolE returns the settings' value for k as a bool. A SettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is not a bool.
func (*Settings) CheckExeDir ¶
CheckExeDir returns if Settings should check the executable directory for the configuration file.
func (*Settings) CheckWD ¶
CheckWD returns if settings should check the working directory for the configuration file.
func (*Settings) ConfFilePathEnvVars ¶
ConfFilePathEnvVars retyrbs the names of the environment variables that have paths that settings should check when looking for the configuration file.
func (*Settings) ConfFilePaths ¶
ConfFilePaths returns the paths that settings should check when looking for the configuration file.
func (*Settings) ConfFilename ¶
ConfFilename returns the settings' configuration filename.
func (*Settings) EnvVarName ¶
EnvVarName returns the environment variable name for k. This will be NAME_K, where K is k and NAME is settings' name.
func (*Settings) ErrOnMissingConfFile ¶
ErrOnMissingConfFile returns if settings is configured to return an error if the configuration file cannot be located.
func (*Settings) Get ¶
Get returns the settings' value for k as an interface{}. A nil is returned if k doesn't exist.
func (*Settings) GetE ¶
GetE returns settings' value for k as an interface{}. A SettingNotFoundError is returned if k doesn't exist.
func (*Settings) GetFormat ¶
GetFormat returns the format to use if the ConfFilename hasn't been explicitly set.
func (*Settings) GetFormatString ¶
GetFormatString returns the format to use if the ConfFilename hasn't been explicitly set as a string
func (*Settings) Int ¶
Int returns the settings' value for k as an int. A 0 will be returned if k either doesn't exist or if its value is nat an int.
func (*Settings) Int64 ¶
Int64 returns the settings value for k as an int64. A 0 will be returned if k doesn't exist or if its value is neither an int64 nor an int.
func (*Settings) Int64E ¶
Int64E returns the settings value for k as an int64. A SettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is neither an int64 nor an int.
func (*Settings) IntE ¶
IntE returns the settings' value for k as an int. A SettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is not an int.
func (*Settings) Interface ¶
Interface returns the settings' value for k as an interface{}. A nil will be returned if k doesn't exist.
func (*Settings) InterfaceE ¶
InterfaceE returns the settings' value for k as an interface{}. A SettingNotFoundError is returned if k doesn't exist.
func (*Settings) IsConfFileVar ¶
IsConfFileVar returns if setting k is a ConfFileVar setting. False will be returned if k doesn't exist in settings.
func (*Settings) IsConfFileVarE ¶
IsConfFileVarE returns if setting k is a ConfFileVar setting. A SettingNotFoundErr will be returned if k doesn't exist in settings.
func (*Settings) IsCore ¶
IsCore returns if setting k is a Core setting. False will be returned if k doesn't exist in settings.
func (*Settings) IsCoreE ¶
IsCoreE returns if setting k is a Core setting. A SettingNotFoundErr will be returned if k doesn't exist in settings.
func (*Settings) IsEnvVar ¶
IsEnvVar returns if setting k is an EnvVar setting. False will be returned if k doesn't exist in settings.
func (*Settings) IsEnvVarE ¶
IsEnvVarE returns if setting k is an EnvVar setting. A SettingNotFoundErr will be returned if k doesn't exist in settings.
func (*Settings) IsFlag ¶
IsFlag returns if setting k is a Flag setting. False will be returned if k doesn't exist in settings.
func (*Settings) IsFlagE ¶
IsFlagE returns if setting k is a Flag setting. A SettingNotFoundErr will be returned if k doesn't exist in settings.
func (*Settings) IsSet ¶
IsSet returns if settings' configuration settings have been set from all of its configured sources.
func (*Settings) ParseFlags ¶
ParseFlags parses the args for the settings. Only settings of type Flag can be set via ParseFlags. Flags have the highest precedence. After parsing, any non-flag args are returned to the caller and a list of flags in the args is cached.
If settings is not set to use flags, the args will be returned along with an ErrUseFlagsFalse. If settings has already parsed flags, the args are returned along with an ErrFlagsParsed.
All of settings' flags must be registered prior to calling ParseFlags.
func (*Settings) RegisterBoolConfFileVar ¶
RegisterBoolConfFileVar registers a bool setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterBoolEnvVar ¶
RegisterBoolEnvVar registers a bool setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterBoolFlag ¶
RegisterBoolFlag registers a bool setting using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterInt64ConfFileVar ¶
RegisterInt64ConfFileVar registers an int64 setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterInt64EnvVar ¶
RegisterInt64EnvVar registers an int64 setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterInt64Flag ¶
RegisterInt64Flag registers an int64 setting using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) RegisterIntConfFileVar ¶
RegisterIntConfFileVar registers an int setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterIntEnvVar ¶
RegisterIntEnvVar registers an int setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterIntFlag ¶
RegisterIntFlag registers an int setting using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) RegisterInterfaceConfFileVar ¶
RegisterInterfaceConfFileVar registers an int setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterSetting ¶
func (s *Settings) RegisterSetting(typ, name, short string, value interface{}, dflt, usage string, IsCore, IsConfFileVar, IsEnvVar, IsFlag bool) error
RegisterSetting registers a setting. For most settings, the data and setting type specific registration and add functions should be used. The exception would be when more granular control over what can update a registered setting is needed. This method allows Is[ConfFileVar|EnvVar|Flag] bools to be set independently.
If a setting with the key k already exists, a SettingExistsError will be returned. If k is an empty string an ErrNoSettingName will be returned.
The short, dflt, and usage parms only apply to settings whose IsFlag bool is true.
For non-Core settings, IsCore must be false. If IsCore is true, k's value cannot be changed after registration, regardless of the truthiness of Is[ConfFileVar|IsEnvVar|IsFlag]. For Core settings, AddCore methods should be used.
If the setting can be updated by a configuration file, environment variable or a flag, the Is[ConfFileVar|IsEnv|IsFlag] bools should be set to true as appropriate. These conditionals are independent; e.g. a setting can have both IsConfFileVar and IsFlag set to true if the setting is not to be updateable from an environment variable.
If Is[Core|ConfFileVar|Env|Flag] are all false, the setting will only be updateable by using the Update methods. For these kind of settings, the usage of Add functions should be preferred. These setting will not be exposed to the configuration file, as an environment variable, or as a flag.
For non string, bool, int, and int64 types, the type must be "interface{}"
func (*Settings) RegisterStringConfFileVar ¶
RegisterStringConfFileVar registers a string setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterStringEnvVar ¶
RegisterStringEnvVar registers a string setting using k for its key and v for its value. Once registered, the value of this setting can only be updated from a configuration file or an environment variable. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned.
func (*Settings) RegisterStringFlag ¶
RegisterStringFlag registers a string setting using k for its key and v for its value. Once registered, the value of this setting can be updated from a configuration file, an environment variable, or a flag. If k already exists a SettingExistsError will be returned. If k is empty, an ErrNoSettingName will be returned
func (*Settings) SearchPATH ¶
SearchPATH returns if settings should use the user's PATH environment variable to check for the configuratiom file.
func (*Settings) Set ¶
Set updates the settings' configuration from a configuration file and environment variables. This is only run once; subsequent calls will result in no changes. Only settings that are of type ConfFileVar or EnvVar will be affected. This does not handle flags.
Once the standard settings has been set, updated, it will not update again; subsequent calls will result in nothing being done.
All ConfFileVar, EnvVar, and Flag settings must be registered before calling
func (*Settings) SetCheckExeDir ¶
SetCheckExeDir sets if Settings should check the executable directory for the configuration file.
func (*Settings) SetCheckWD ¶
SetCheckWD sets if settings should check the working directory for the configuration file.
func (*Settings) SetConfFilePathEnvVars ¶
SetConfFilePathEnvVars sets the names of the environment variables that have paths that settings should check when looking for the configuration file. The environment variables will be checked in the order provided. The environment variables may contain multiple paths.
func (*Settings) SetConfFilePaths ¶
SetConfFilePaths sets the paths that settings should check when looking for the configuration file. The paths will be checked in the order provided.
func (*Settings) SetConfFilename ¶
SetConfFilename sets the settings' configuration filename and configures settings to use a configuration file. If the filename is empty, an error is returned. If the filename's extension isn't parsable to a supported configuration format, an UnsupportedFormatError is returned.
func (*Settings) SetErrOnMissingConfFile ¶
SetErrOnMissingConfFile sets if settings should return an error if the confiugration file cannot be located.
func (*Settings) SetFormat ¶
SetFormat sets the format to use for the conffile if the ConfFilename hasn't been explicitly set.
func (*Settings) SetFormatString ¶
SetFormatString sets the format, using a string, to use for the configuration file if the ConfFilename hasn't been explicitly set. If the string isn't parsable to a supported Format, an UnsupportedFormatError will be returned.
func (*Settings) SetFromConfFile ¶
SetFromConfFile updates the settings' configuration from the configuration file. If the configuration filename was not set using the SetConfFilename method, settings will look for the configuration file using the settings' name and it's format: name.format.
The format, in full, is used as the extension, i.e. JSON's extension will be 'json', TOML's extension will be 'toml', and YAML's extension will be 'yaml'.
Once the settings has been set, updated from the configuration file, they will not be updated again from the configuration file; subsequent calls will result in nothing being done.
The settings will look for the configuration file according to how it's been configured.
filename confFilePaths + filename confFileEnvVars + filename (each env var may have multiple path elements) working directory + filename executable directory + filename $PATH element + filename (PATH may have multiple path elements)
Any of the above elements that are either empty or false are skipped.
If the file cannot be found, an os.PathError with an os.ErrNotExist and a list of all paths checked is returned.
func (*Settings) SetFromEnvVars ¶
SetFromEnvVars updates the settings' configuration from environment variables.
Once the standard settings has been set, updated, from environment variables, they will not be updated again from environment variables; subsequent calls will result in nothing being done.
A setting's env name is a concatonation of the settings' name, an underscore (_), and the setting's key, e.g. given a settings with the name 'foo', a setting whose key is 'bar' will be updateable with the environment variable FOO_BAR.
func (*Settings) SetSearchPATH ¶
SetSearchPATH sets if settings should use the user's PATH environment variable to check for the configuratiom file.
func (*Settings) SetUsage ¶
func (s *Settings) SetUsage(f func())
SetUsage sets settings' Usage func.
func (*Settings) String ¶
String returns the settings value for k as a string. An empty string, "", will be returned if k either doesn't exist or if its value is not a string.
func (*Settings) StringE ¶
StringE returns the settings value for k as a string. A SettingNotFoundError is returned if k doesn't exist. A DataTypeError will be returned if the value is not a string.
func (*Settings) UpdateBool ¶
UpdateBool updates k with a boo, v. If settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func (*Settings) UpdateInt ¶
UpdateInt updates k with an int, v. If settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func (*Settings) UpdateInt64 ¶
UpdateInt64 updates k with an int64, v. If settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func (*Settings) UpdateInterface ¶
UpdateInterface updates k with an interface, v. If settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func (*Settings) UpdateString ¶
UpdateString updates k with a string, v. If settings does not have a setting k, both a false and a SettingNotFoundError will be returned. If the setting k is not updateable, both a false and either a CoreUpdateError or an UpdateError will be returned.
func (*Settings) UseConfFile ¶
UseConfFile returns if settings will update its configuration settings from a configuration file.
func (*Settings) UseEnvVars ¶
UseEnvVars returns if settings will update its configuration settings from environment variables.
func (*Settings) UseFlags ¶
UseFlags returns if settings has any flags that can be updated using ParseFlags.
func (*Settings) Visited ¶
Visited returns the names of all settings' flags that were set during flag parsing, in lexical order.
func (*Settings) WasVisited ¶
WasVisited returns if settings' flag k was processed during flag parsing.
type ShortFlagExistsError ¶
type ShortFlagExistsError struct {
// contains filtered or unexported fields
}
ShortFlagExistsError occurs when registering a flag whose short flag already exists/
func (ShortFlagExistsError) Error ¶
func (e ShortFlagExistsError) Error() string
type UnsupportedFormatError ¶
type UnsupportedFormatError struct {
// contains filtered or unexported fields
}
UnsupportedFormatError occurs when the string cannot be matched to a supported configuration format.
func NewUnsupportedFormatError ¶
func NewUnsupportedFormatError(s string) UnsupportedFormatError
NewUnsupportedFormatError returns an UnsupportedFormatError using the provided s.
func (UnsupportedFormatError) Error ¶
func (e UnsupportedFormatError) Error() string
type UpdateError ¶
type UpdateError struct {
// contains filtered or unexported fields
}
UpdateError records information about an Update operation that results in an error that isn't neither a SettingNotFoundError nor a CoreUpdateError.
func (UpdateError) Error ¶
func (e UpdateError) Error() string