-
Notifications
You must be signed in to change notification settings - Fork 3
/
match.go
29 lines (25 loc) · 1017 Bytes
/
match.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
package main
import (
"github.com/gentlemanautomaton/stathat"
"github.com/gentlemanautomaton/stathat/statmatch"
)
// Match provides stat name inclusion and exclusion filters for commands.
type Match struct {
Include []statmatch.Pattern `kong:"env='INCLUDE',name='include',help='Include stats with names matching regular expression pattern.'"`
Exclude []statmatch.Pattern `kong:"env='EXCLUDE',name='exclude',help='Exclude stats with names matching regular expression pattern.'"`
}
// Empty returns true if the match is unspecified.
func (m Match) Empty() bool {
return len(m.Include) == 0 && len(m.Exclude) == 0
}
// Filter returns a stathat filter for m.
func (m Match) Filter() stathat.Filter {
var includes, excludes []stathat.Filter
for _, pattern := range m.Include {
includes = append(includes, statmatch.Name(pattern))
}
for _, pattern := range m.Exclude {
excludes = append(excludes, statmatch.Name(pattern))
}
return statmatch.All(statmatch.Any(includes...), statmatch.None(excludes...))
}