diff --git a/README.md b/README.md index 8ad8793..78c31f7 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,6 @@ Usage of twitch-bot: --storage-file string Where to store the data (default "./storage.json.gz") --twitch-client string Client ID to act as --twitch-token string OAuth token valid for client + -v, --validate-config Loads the config, logs any errors and quits with status 0 on success --version Prints current version and exits ``` diff --git a/main.go b/main.go index 205cb16..40649cb 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ var ( StorageFile string `flag:"storage-file" default:"./storage.json.gz" description:"Where to store the data"` TwitchClient string `flag:"twitch-client" default:"" description:"Client ID to act as"` TwitchToken string `flag:"twitch-token" default:"" description:"OAuth token valid for client"` + ValidateConfig bool `flag:"validate-config,v" default:"false" description:"Loads the config, logs any errors and quits with status 0 on success"` VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` }{} @@ -66,6 +67,17 @@ func init() { func main() { var err error + if err = loadConfig(cfg.Config); err != nil { + log.WithError(err).Fatal("Initial config load failed") + } + defer func() { config.CloseRawMessageWriter() }() + + if cfg.ValidateConfig { + // We were asked to only validate the config, this was successful + log.Info("Config validated successfully") + return + } + if err = startCheck(); err != nil { log.WithError(err).Fatal("Missing required parameters") } @@ -74,11 +86,6 @@ func main() { log.WithError(err).Fatal("Unable to load storage file") } - if err = loadConfig(cfg.Config); err != nil { - log.WithError(err).Fatal("Initial config load failed") - } - defer func() { config.CloseRawMessageWriter() }() - fsEvents := make(chan configChangeEvent, 1) go watchConfigChanges(cfg.Config, fsEvents)