mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
Add validation mode for config
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
890242845c
commit
71c708570c
2 changed files with 13 additions and 5 deletions
|
@ -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
|
||||
```
|
||||
|
|
17
main.go
17
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue