-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_update.go
47 lines (37 loc) · 859 Bytes
/
cmd_update.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
package main
type CmdUpdate struct{}
func init() {
_, err := parser.AddCommand("update",
"update outputs",
"The update command updates the outputs as configured",
&CmdUpdate{})
if err != nil {
panic(err)
}
}
func MatchRules(rules []Rule, outputs Outputs) (Rule, error) {
for _, rule := range rules {
if rule.Match(outputs) {
return rule, nil
}
}
return Rule{}, nil
}
func (cmd CmdUpdate) Execute(args []string) (err error) {
err = globalOpts.ReadConfigfile()
if err != nil {
return err
}
// install panic handler if commands are given
defer RunCommandsOnFailure(&err, globalOpts.cfg.OnFailure)()
outputs, err := DetectOutputs()
if err != nil {
return err
}
rule, err := MatchRules(globalOpts.cfg.Rules, outputs)
if err != nil {
return err
}
V("rule %q matches\n", rule.Name)
return ApplyRule(outputs, rule)
}