From e384f6fce9200a64e3195f2f235d5e5b75f81f58 Mon Sep 17 00:00:00 2001 From: Arnar Gauti Ingason Date: Sat, 12 Oct 2019 17:35:25 +0000 Subject: [PATCH] Adding the ability to specify flags with environment variables --- main.go | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 053ad4f..5a04e74 100644 --- a/main.go +++ b/main.go @@ -115,36 +115,43 @@ func main() { flags := []cli.Flag{ cli.StringFlag{ - Name: "config-path, c", - Value: "/etc/plex_exporter/config.yaml", - Usage: "Path config file", + Name: "config-path, c", + Value: "/etc/plex_exporter/config.yaml", + Usage: "Path config file", + EnvVar: "PLEX_CONFIG_PATH,CONFIG_PATH", }, cli.StringFlag{ - Name: "listen-address, l", - Value: ":9594", - Usage: "Port for server", + Name: "listen-address, l", + Value: ":9594", + Usage: "Port for server", + EnvVar: "PLEX_LISTEN_ADDR,LISTEN_ADDR,ADDR", }, cli.StringFlag{ - Name: "log-level", - Value: "info", - Usage: "Verbosity level of logs", + Name: "log-level", + Value: "info", + Usage: "Verbosity level of logs", + EnvVar: "PLEX_LOG_LEVEL,LOG_LEVEL", }, cli.StringFlag{ - Name: "format, f", - Value: "text", - Usage: "Output format of logs", + Name: "format, f", + Value: "text", + Usage: "Output format of logs", + EnvVar: "PLEX_LOG_FORMAT,LOG_FORMAT", }, cli.BoolFlag{ - Name: "auto-discover, a", - Usage: "Auto discover Plex servers from plex.tv", + Name: "auto-discover, a", + Usage: "Auto discover Plex servers from plex.tv", + EnvVar: "PLEX_AUTO_DISCOVER,AUTO_DISCOVER", }, cli.StringFlag{ - Name: "plex-server, p", - Usage: "Address of Plex Media Server", + Name: "plex-server, p", + Usage: "Address of Plex Media Server", + EnvVar: "PLEX_SERVER", }, cli.StringFlag{ - Name: "token, t", - Usage: "Authentication token for Plex Media Server", + Name: "token, t", + Usage: "Authentication token for Plex Media Server", + EnvVar: "PLEX_TOKEN,TOKEN", }, }