diff options
Diffstat (limited to 'cmd/print-config/main.go')
-rw-r--r-- | cmd/print-config/main.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/cmd/print-config/main.go b/cmd/print-config/main.go new file mode 100644 index 0000000..f81eb82 --- /dev/null +++ b/cmd/print-config/main.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "sort" + + "go.eth.moe/dispatch/config" + "go.eth.moe/flag" + "go.eth.moe/logger" +) + +var ( + configPath = flag.Custom("config-path", "", "path to config.json", flag.RequiredString) +) + +func main() { + flag.Parse() + + configPath := (*configPath).(string) + + log := logger.Background() + + cfg, err := config.ParseFile(configPath) + if err != nil { + log.AddField("config-path", configPath) + log.WithError(err).Fatal("could not parse config") + } + + var names []string + for name := range cfg.RulesByName { + names = append(names, name) + } + sort.Strings(names) + + for _, name := range names { + rule := cfg.RulesByName[name] + + fmt.Printf("%v:\n", name) + fmt.Printf("- triggers:\n") + for _, trigger := range rule.Triggers { + fmt.Printf(" - url: %v\n", trigger.URL) + } + fmt.Printf("- actions:\n") + for _, action := range rule.Actions { + switch action.Kind { + case config.HTTPAction: + fmt.Printf(" - url: %v\n", action.URL) + case config.MQTTAction: + fmt.Printf(" - mqtt: %v\n", action.MQTT) + fmt.Printf(" - value: %v\n", action.Value) + } + } + } +} |