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