diff --git a/main.go b/main.go index c77e355..be14267 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "github.com/thoj/go-ircevent" "os" "os/signal" + "strings" "syscall" ) @@ -20,6 +21,12 @@ var log = loggo.GetLogger("main") var branch string var revision string +var CONFIG_FILE_LOCATIONS = []string{ + "/etc", + "/run/secrets", + ".", +} + type IRCCat struct { auth_channel string channels mapset.Set @@ -31,19 +38,24 @@ type IRCCat struct { func main() { debug := flag.Bool("debug", false, "Print raw IRC lines") + configFile := flag.String("config", "", "Path to config file to use") flag.Parse() loggo.ConfigureLoggers("=INFO") log.Infof("IRCCat %s (%s) starting...", branch, revision) - viper.SetConfigName("irccat") - viper.AddConfigPath("/run/secrets") - viper.AddConfigPath("/etc") - viper.AddConfigPath(".") + if *configFile != "" { + viper.SetConfigFile(*configFile) + } else { + viper.SetConfigName("irccat") + for _, p := range CONFIG_FILE_LOCATIONS { + viper.AddConfigPath(p) + } + } var err error err = viper.ReadInConfig() if err != nil { - log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in . or /etc") + log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in one of %s", strings.Join(CONFIG_FILE_LOCATIONS, ", ")) return }