aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthel Morgan <eth@ethulhu.co.uk>2020-08-05 15:57:44 +0100
committerEthel Morgan <eth@ethulhu.co.uk>2020-08-05 15:57:44 +0100
commit147e14137215bfae901c1d0369706eee3700acd5 (patch)
treec4d777be110bfcea8bb098438e7e08372d03a1a4
parent1254c353241f6afcf3dd958088629d9fe2f5cb75 (diff)
add cmd/print-config, to print a parsed configHEADlatest
-rw-r--r--cmd/print-config/main.go54
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)
+ }
+ }
+ }
+}