Documentation ¶
Index ¶
- Constants
- Variables
- func Apply()
- func ApplyFromFlags(pflags *pflag.FlagSet)
- func Debug() bool
- func InitConfig()
- func ResetBindings()
- func Set(bk string, value interface{})
- func SetDebug(b bool)
- func ToggleDebug() bool
- func ToggleVerbose() bool
- func UpdateChangedFlags()
- func Verbose() bool
- type BindFlag
Constants ¶
const ( DebugKey = "debug" // bool VerboseKey = "verbose" // bool )
These are top level variables in, say, a YAML file. e.g. debug = true not: vconfig: debug: true
Variables ¶
var ( ConfigFileName string ConfigFileRoot string HistoryFile string )
var (
AppName = "application"
)
Functions ¶
func Apply ¶
func Apply()
Apply will set the viper variable with BindKey to the Value if there is a Value.
func ApplyFromFlags ¶
ApplyFromFlags will look at each flag in the flag set and if the flag changed and there is a Binding it will set the viper value to the value of the flag (not the BindValue). This is where precedence is maintained essentially allowing for a switch having flags take short-term preccedence over sets.
func ResetBindings ¶
func ResetBindings()
ResetBindings will erase existing bindings. This is really used for Testing.
func Set ¶
func Set(bk string, value interface{})
Set will set the viper variable and keep the value for later application during Apply.
func ToggleVerbose ¶
func ToggleVerbose() bool
ToggleVerbose toggles the flag and returns the new value.
func UpdateChangedFlags ¶
func UpdateChangedFlags()
UpdateChangedFlags will look at each binding and if the associated flag has changed, udpate the bind value. This is intended to be used to capture values to bind to viper right after a parse of flags has acurred. You might then immediately call Apply() to cause the viper variables to take this new value. This is different behavior than ApplyFromFlags.
Types ¶
type BindFlag ¶
BindFlag - structure for dealing with values that propogate from the app command line flags.
func Bind ¶
Bind a flag key to a flag variable. The reason we're doing this is because the viper pFlags integration doesn't doesn't comprehend multiple invocations. So, the first a key is bound to a flag, a new BindEntry is created. After that if a bind entry already exists, only the flag will be updated.
func GetBindFlags ¶
func GetBindFlags() (bfs []*BindFlag)
GetBindFlags returns all the BindFlags registered.