-
Notifications
You must be signed in to change notification settings - Fork 23
/
rule.go
53 lines (41 loc) · 1.18 KB
/
rule.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
53
package main
// Rule is a rule to configure outputs.
type Rule struct {
Name string
OutputsConnected []string `yaml:"outputs_connected"`
OutputsDisconnected []string `yaml:"outputs_disconnected"`
OutputsPresent []string `yaml:"outputs_present"`
OutputsAbsent []string `yaml:"outputs_absent"`
ConfigureRow []string `yaml:"configure_row"`
ConfigureColumn []string `yaml:"configure_column"`
ConfigureSingle string `yaml:"configure_single"`
ConfigureCommand string `yaml:"configure_command"`
Primary string `yaml:"primary"`
DisableOrder []string `yaml:"disable_order"`
Atomic bool `yaml:"atomic"`
ExecuteAfter []string `yaml:"execute_after"`
}
// Match returns true iff the rule matches for the given list of outputs.
func (r Rule) Match(outputs Outputs) bool {
for _, name := range r.OutputsAbsent {
if outputs.Present(name) {
return false
}
}
for _, name := range r.OutputsDisconnected {
if outputs.Connected(name) {
return false
}
}
for _, name := range r.OutputsPresent {
if !outputs.Present(name) {
return false
}
}
for _, name := range r.OutputsConnected {
if !outputs.Connected(name) {
return false
}
}
return true
}