1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00
woodpecker/vendor/github.com/ianschenck/envflag
2016-04-11 15:55:13 -07:00
..
envflag.go updated logrus 2016-04-11 15:55:13 -07:00
LICENSE updated logrus 2016-04-11 15:55:13 -07:00
README.md updated logrus 2016-04-11 15:55:13 -07:00

envflag

Golang flags, but bolted onto the environment rather than the command-line.

Read the godocs.

Motivation

Some like the distinction that command-line flags control behavior while environment variables configure. Also 12-factor recommends the use of environment variables for configuration. The interface of the golang flag package is well designed and easy to use, and allows for other lists (os.Environ() vs os.Args) to be parsed as flags. It makes sense then to use the same interface, the same types, and the same parsing (caveat: there is some ugly string hacking to make environment variables look like flags) to the same ends.

Differences

Calling flag.Parse() will not parse environment flags. Calling envflag.Parse() will not parse command-line flags. There is no good reason to combine these two when the net savings is a single line in a func main(). Furthermore, doing so would require users to accept a precedence order of my choosing.

The presence of an environment variable named h or help will probably cause problems (print Usage and os.Exit(0)). Work around this by defining those flags somewhere (and ignoring them).

Before calling Flagset.Parse on EnvironmentFlags, the environment variables being passed to Parse are trimmed down using Lookup. This behavior is different from flag.Parse in that extra environment variables are ignored (and won't crash envflag.Parse).