Documentation ¶
Overview ¶
Package flagenv implements a simple way to expose all your flags as environmental variables.
Commandline flags have more precedence over environment variables. In order to use it just call flagenv.SetFlagsFromEnv from an init function or from your main.
You can call it either before or after your your flag.Parse invocation.
This example will make it possible to set the default of --my_flag also via the MY_PROG_MY_FLAG env var:
var myflag = flag.String("my_flag", "", "some flag") func init() { flagenv.SetFlagsFromEnv("MY_PROG", flag.CommandLine) } func main() { flags.Parse() ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetFlagsFromEnv ¶
SetFlagsFromEnv sets flag values from environment, e.g. PREFIX_FOO_BAR set -foo_bar. It sets only flags that haven't been set explicitly. The defaults are preserved and -help will still show the defaults provided in the code.
Types ¶
This section is empty.