Documentation
¶
Overview ¶
Package dockerflags provides helper functions useful to handle commandline flags in CLI tools used inside Docker containers.
The functions follow a general pattern: Their first parameter is the same as in corresponding functions from the standard `flag` package. The second parameter is the name of an environment variable used to override the default for that flag, the third parameter is the flag name, corresponding to the second parameter in `flag` package functions, followed by the normal default value and the description. Each function appends a small note to the description before passing it to the `flag` package function, informing the user about the environment variable that can override the default.
Generally, the priority order is (from lowest priority to highest):
- Default value passed to `dockerflags` function.
- Value from the environment variable (if set and parseable to the given type).
- flag value given on commandline.
Additionally, helper function to just lookup and parse environment variables are provided. These log a warning if the environment variable is set but the content can't be parsed to the relevant type. Note that there is no lookup function for strings, as that would just be the same as os.LookupEnv.
Index ¶
- Variables
- func BoolVar(target *bool, envVar, flagname string, defaultval bool, description string)
- func DurationVar(target *time.Duration, envVar, flagname string, defaultval time.Duration, ...)
- func Float64Var(target *float64, envVar, flagname string, defaultval float64, ...)
- func FsBoolVar(fs *flag.FlagSet, target *bool, envVar, flagname string, defaultval bool, ...)
- func FsDurationVar(fs *flag.FlagSet, target *time.Duration, envVar, flagname string, ...)
- func FsFloat64Var(fs *flag.FlagSet, target *float64, envVar, flagname string, defaultval float64, ...)
- func FsInt64Var(fs *flag.FlagSet, target *int64, envVar, flagname string, defaultval int64, ...)
- func FsIntVar(fs *flag.FlagSet, target *int, envVar, flagname string, defaultval int, ...)
- func FsStringVar(fs *flag.FlagSet, target *string, ...)
- func Int64Var(target *int64, envVar, flagname string, defaultval int64, description string)
- func IntVar(target *int, envVar, flagname string, defaultval int, description string)
- func LookupBoolEnv(s string) (bool, error)
- func LookupDurationEnv(s string) (time.Duration, error)
- func LookupFloat64Env(s string) (float64, error)
- func LookupInt64Env(s string) (int64, error)
- func LookupIntEnv(s string) (int, error)
- func StringVar(target *string, envVar, flagname, defaultval, description string)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
var ErrorDuringEnvParsing error
This is set to the last error that occurred while parsing environment variables into defaults, but only if the error is not ErrNotFound.
Functions ¶
func DurationVar ¶
func DurationVar(target *time.Duration, envVar, flagname string, defaultval time.Duration, description string)
DurationVar calls FsDurationVar with the flag.CommandLine flagset.
func Float64Var ¶
Float64Var calls FsFloat64Var with the flag.CommandLine flagset.
func FsBoolVar ¶
func FsBoolVar(fs *flag.FlagSet, target *bool, envVar, flagname string, defaultval bool, description string)
FsBoolVar sets up a flag.BoolVar that uses the value from the OS environment variable envVar as the default if it is set and parseable as a bool, otherwise with the specified default value.
func FsDurationVar ¶
func FsDurationVar(fs *flag.FlagSet, target *time.Duration, envVar, flagname string, defaultval time.Duration, description string)
FsDurationVar sets up a flag.DurationVar in the given flagset, using the value from the OS environment variable envVar as the default if it is set and parseable as a time.Duration, otherwise with the specified default value.
func FsFloat64Var ¶
func FsFloat64Var(fs *flag.FlagSet, target *float64, envVar, flagname string, defaultval float64, description string)
FsFloat64Var sets up a flag.Float64Var that uses the value from the OS environment variable envVar as the default if it is set and parseable as a float64, otherwise with the specified default value.
func FsInt64Var ¶
func FsInt64Var(fs *flag.FlagSet, target *int64, envVar, flagname string, defaultval int64, description string)
FsInt64Var sets up a flag.Int64Var that uses the value from the OS environment variable envVar as the default if it is set and parseable as an int64, otherwise with the specified default value.
func FsIntVar ¶
func FsIntVar(fs *flag.FlagSet, target *int, envVar, flagname string, defaultval int, description string)
FsIntVar sets up a flag.IntVar that uses the value from the OS environment variable envVar as the default if it is set and parseable as an int, otherwise with the specified default value.
func FsStringVar ¶
func FsStringVar(fs *flag.FlagSet, target *string, envVar, flagname, defaultval, description string)
FsStringVar sets up a flag.StringVar in the given flagset, using the value from the OS environment variable envVar as the default if the variable is set.
func LookupBoolEnv ¶
LookupBoolEnv looks up environment variable s and converts it to a bool.
func LookupDurationEnv ¶
LookupDurationEnv looks up environment variable s and converts it to a time.Duration.
func LookupFloat64Env ¶
LookupFloat64Env looks up environment variable s and converts it to a float64.
func LookupInt64Env ¶
LookupInt64Env looks up environment variable s and converts it to an int64.
func LookupIntEnv ¶
LookupIntEnv looks up environment variable s and converts it to an int64.
Types ¶
This section is empty.