-
Notifications
You must be signed in to change notification settings - Fork 23
/
cmd_rules.go
52 lines (43 loc) · 1.11 KB
/
cmd_rules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import "fmt"
type CmdRules struct{}
func init() {
_, err := parser.AddCommand("rules",
"list rules",
"The rules command lists the configured rules",
&CmdRules{})
if err != nil {
panic(err)
}
}
func printList(label string, args []string) {
if len(args) > 0 {
fmt.Printf(" %s: %v\n", label, args)
}
}
func printOne(label string, arg string) {
if len(arg) > 0 {
fmt.Printf(" %s: %v\n", label, arg)
}
}
func (cmd CmdRules) Execute(args []string) error {
err := globalOpts.ReadConfigfile()
if err != nil {
return err
}
for _, rule := range globalOpts.cfg.Rules {
fmt.Printf("%v\n", rule.Name)
if globalOpts.Verbose {
printList("Connected", rule.OutputsConnected)
printList("Disconnected", rule.OutputsDisconnected)
printList("Present", rule.OutputsPresent)
printList("Absent", rule.OutputsAbsent)
printList("ConfigureRow", rule.ConfigureRow)
printList("ConfigureColumn", rule.ConfigureColumn)
printOne("ConfigureSingle", rule.ConfigureSingle)
printOne("ConfigureCommand", rule.ConfigureCommand)
printList("ExecuteAfter", rule.ExecuteAfter)
}
}
return nil
}