Documentation ¶
Index ¶
- Variables
- func AddTopLevelFlags(flags *pflag.FlagSet)
- func EnvNameForFlag(prefix string, flag *pflag.Flag) string
- func InitLogging()
- func LogFlagError(flagName string, err error)
- func New(cmdName, cmdDescription string) *cobra.Command
- func NewUsingCmd(rootCmd *cobra.Command) *cobra.Command
- func SetFlagsFromEnv(prefix string, flags *pflag.FlagSet)
- func SetFlagsFromEnvWithOverrides(prefix string, flagSet *pflag.FlagSet, overrides map[string]string)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorLogInitFailure is the error logged when the initial log configuration setup fails ErrorLogInitFailure = fmt.Errorf("failure during logging init") // ErrorLogLevelParse is the error logged when the specified log level cannot be parsed ErrorLogLevelParse = fmt.Errorf("unable to parse specified log level") // ErrorLogUnknownFormat is the error logged when an unrecognized log format is specified ErrorLogUnknownFormat = fmt.Errorf("unknown log format specified") )
var ( // ErrorFlagCannotRetrieve is the error logged when attempting to retrieve the value of a flag fails ErrorFlagCannotRetrieve = fmt.Errorf("cannot retrieve flag value") )
Functions ¶
func AddTopLevelFlags ¶
AddTopLevelFlags takes a pointer to an existing pflag.FlagSet and adds the default top level flags to it
func EnvNameForFlag ¶
EnvNameForFlag generates an expected environment variable name, given the provided prefix and flag
func InitLogging ¶ added in v0.0.2
func InitLogging()
func LogFlagError ¶
LogFlagError generates a log entry for an error related to retrieving a flag value
func NewUsingCmd ¶
NewUsingCmd takes an existing Cobra command and adds in the default flags, subcommands, and Init/Run entries
func SetFlagsFromEnv ¶
SetFlagsFromEnv calls SetFlagsFromEnvWithOverrides and passes an empty overrides map
func SetFlagsFromEnvWithOverrides ¶
func SetFlagsFromEnvWithOverrides(prefix string, flagSet *pflag.FlagSet, overrides map[string]string)
SetFlagsFromEnvWithOverrides sets the default value for each flag in the flagset based on a matching environment variable. The expected env var name will be the flag's name, all uppercase, with hyphens replaced by underscores (i.e. flag "foo-bar" will be matched with env var "FOO_BAR") If set, prefix will be appended to the expected name of each env variable (i.e. prefix of baz and flag "foobar" will be marched with env var "BAZ_FOOBAR") If overrides has a key that matches the flag name, the value of that key will be used as the expected env var name (i.e. override entry of "foobar=MY_SPECIAL_FLAG" will result in the flag "foobar" being matched with the env var "MY_SPECIAL_FLAG") Override is for when you want all the flags to have a prefix, but need some specific flags to not use that prefix (or have different env vars entirely). For example, having the application recognize a standard env var like "REDIS_URL" while prefacing most app specific flags with APPNAME_
Types ¶
This section is empty.