allow to specify CLI options via environment vars

Use `git show -w` to inspect this commit diff since
it changes whitespace due to `gofmt`.

This commit allows to use environment variables in place of
CLI parameters to change program behavior. This supports the
notion of [12-factor apps](http://12factor.net/)
and makes it easier to dockerize the app as well as create
a systemd unit file.

It establishes a pattern of `MGMT_*` naming convention
for environment variables.
This commit is contained in:
Paul Morgan
2016-04-26 00:51:55 +00:00
parent 2654384461
commit 3120628d8a

View File

@@ -228,6 +228,7 @@ func main() {
Name: "file, f", Name: "file, f",
Value: "", Value: "",
Usage: "graph definition to run", Usage: "graph definition to run",
EnvVar: "MGMT_FILE",
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "no-watch", Name: "no-watch",
@@ -259,16 +260,19 @@ func main() {
Name: "seed, s", Name: "seed, s",
Value: "", Value: "",
Usage: "default etc peer endpoint", Usage: "default etc peer endpoint",
EnvVar: "MGMT_SEED_ENDPOINT",
}, },
cli.IntFlag{ cli.IntFlag{
Name: "converged-timeout, t", Name: "converged-timeout, t",
Value: -1, Value: -1,
Usage: "exit after approximately this many seconds in a converged state", Usage: "exit after approximately this many seconds in a converged state",
EnvVar: "MGMT_CONVERGED_TIMEOUT",
}, },
cli.IntFlag{ cli.IntFlag{
Name: "max-runtime", Name: "max-runtime",
Value: 0, Value: 0,
Usage: "exit after a maximum of approximately this many seconds", Usage: "exit after a maximum of approximately this many seconds",
EnvVar: "MGMT_MAX_RUNTIME",
}, },
}, },
}, },