From 3120628d8a43997194d7b6e2a41ea24c611e4ee0 Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Tue, 26 Apr 2016 00:51:55 +0000 Subject: [PATCH] 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. --- main.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 4a670b44..2faec842 100644 --- a/main.go +++ b/main.go @@ -225,9 +225,10 @@ func main() { Action: run, Flags: []cli.Flag{ cli.StringFlag{ - Name: "file, f", - Value: "", - Usage: "graph definition to run", + Name: "file, f", + Value: "", + Usage: "graph definition to run", + EnvVar: "MGMT_FILE", }, cli.BoolFlag{ Name: "no-watch", @@ -256,19 +257,22 @@ func main() { }, // if empty, it will startup a new server cli.StringFlag{ - Name: "seed, s", - Value: "", - Usage: "default etc peer endpoint", + Name: "seed, s", + Value: "", + Usage: "default etc peer endpoint", + EnvVar: "MGMT_SEED_ENDPOINT", }, cli.IntFlag{ - Name: "converged-timeout, t", - Value: -1, - Usage: "exit after approximately this many seconds in a converged state", + Name: "converged-timeout, t", + Value: -1, + Usage: "exit after approximately this many seconds in a converged state", + EnvVar: "MGMT_CONVERGED_TIMEOUT", }, cli.IntFlag{ - Name: "max-runtime", - Value: 0, - Usage: "exit after a maximum of approximately this many seconds", + Name: "max-runtime", + Value: 0, + Usage: "exit after a maximum of approximately this many seconds", + EnvVar: "MGMT_MAX_RUNTIME", }, }, },