From f599616700069abef0d5338ab453928422d4804e Mon Sep 17 00:00:00 2001 From: Sig Lange Date: Sun, 24 Jan 2016 11:11:57 -0800 Subject: [PATCH] allow config file override --- cmd/runitcmd/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/runitcmd/main.go b/cmd/runitcmd/main.go index 7239d5e..1ed6fd3 100644 --- a/cmd/runitcmd/main.go +++ b/cmd/runitcmd/main.go @@ -29,6 +29,10 @@ func main() { } app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Usage: "override configuration file", + }, cli.StringFlag{ Name: "level, l", Value: "WARN", @@ -47,10 +51,18 @@ func main() { app.Before = func(c *cli.Context) error { gologging.SetLogLevel(c.String("level")) + config_file := c.String("config") config_files := []string{ "/etc/runitcmd.yaml", - filepath.Join(os.Getenv("HOME"), ".runitcmd.yaml"), } + + user_config := filepath.Join(os.Getenv("HOME"), ".runitcmd.yaml") + if config_file == "" { + config_files = append(config_files, user_config) + } else { + config_files = []string{config_file} + } + app.Conf = GetDefaultConfig() for _, config_file := range config_files { _, err := os.Stat(config_file)