envflag

Configure flags from the environment
Log | Files | Refs | README | LICENSE

README.md (777B)


      1 # Environment variables and flags
      2 
      3 Set flags using the standard library `flag` package, and complement them with 
      4 environment variables.
      5 
      6 - All Go's standard `flag` functions are used as normal and parse errors are
      7   returned as expected.
      8 
      9 - Flags, if set, take precedence over the environment.
     10 
     11 - Environment variables can have custom prefixes and suffixes.
     12 
     13 - Usage output can be displayed with the standard `-h` flag.
     14 
     15 - Usage output can be annotated with the configured environment variables.
     16 
     17 ```go
     18 fs := flag.NewFlagSet("test", flag.ContinueOnError)
     19 fs.String("db", "", "Database thing")
     20 _ = envflag.ParseFlagSet(fs, envflag.Prefix("APP_"), envflag.UsageSuffixer())
     21 ```
     22 
     23 produces the following usage
     24 
     25 ```sh
     26 Usage of test:
     27   -db string
     28         Database thing [APP_DB]
     29 ```