@@ -12,15 +12,16 @@ import (
12
12
"regexp"
13
13
"sort"
14
14
"strings"
15
- )
16
15
17
- // TODO: configurable log verbosity.
16
+ "github.com/sirupsen/logrus"
17
+ )
18
18
19
19
type options struct {
20
20
numChunks int
21
21
printChunk int
22
22
printDebug bool
23
23
writer io.Writer
24
+ logLevel string
24
25
}
25
26
26
27
func main () {
@@ -30,6 +31,7 @@ func main() {
30
31
flag .IntVar (& opts .numChunks , "chunks" , 1 , "Number of chunks to create focus regexps for" )
31
32
flag .IntVar (& opts .printChunk , "print-chunk" , 0 , "Chunk to print a regexp for" )
32
33
flag .BoolVar (& opts .printDebug , "print-debug" , false , "Print all spec prefixes in non-regexp format. Use for debugging" )
34
+ flag .StringVar (& opts .logLevel , "log-level" , logrus .ErrorLevel .String (), "Configure the logging level" )
33
35
flag .Parse ()
34
36
35
37
if opts .printChunk >= opts .numChunks {
@@ -60,7 +62,14 @@ func exitIfErr(err error) {
60
62
}
61
63
62
64
func (opts options ) run (dir string ) error {
63
- describes , err := findDescribes (dir )
65
+ level , err := logrus .ParseLevel (opts .logLevel )
66
+ if err != nil {
67
+ return fmt .Errorf ("failed to parse the %s log level: %v" , opts .logLevel , err )
68
+ }
69
+ logger := logrus .New ()
70
+ logger .SetLevel (level )
71
+
72
+ describes , err := findDescribes (logger , dir )
64
73
if err != nil {
65
74
return err
66
75
}
@@ -88,7 +97,7 @@ func (opts options) run(dir string) error {
88
97
// like https://github.com/operator-framework/operator-lifecycle-manager/pull/1476 does.
89
98
var topDescribeRE = regexp .MustCompile (`var _ = Describe\("(.+)", func\(.*` )
90
99
91
- func findDescribes (dir string ) ([]string , error ) {
100
+ func findDescribes (logger logrus. FieldLogger , dir string ) ([]string , error ) {
92
101
// Find all Ginkgo specs in dir's test files.
93
102
// These can be grouped independently.
94
103
describeTable := make (map [string ]struct {})
@@ -103,14 +112,14 @@ func findDescribes(dir string) ([]string, error) {
103
112
}
104
113
specNames := topDescribeRE .FindAllSubmatch (b , - 1 )
105
114
if len (specNames ) == 0 {
106
- log . Printf ("%s: found no top level describes, skipping" , match )
115
+ logger . Warnf ("%s: found no top level describes, skipping" , match )
107
116
continue
108
117
}
109
118
for _ , possibleNames := range specNames {
110
119
if len (possibleNames ) != 2 {
111
- log . Printf ("%s: expected to find 2 submatch, found %d:" , match , len (possibleNames ))
120
+ logger . Debugf ("%s: expected to find 2 submatch, found %d:" , match , len (possibleNames ))
112
121
for _ , name := range possibleNames {
113
- log . Printf ("\t %s\n " , string (name ))
122
+ logger . Debugf ("\t %s\n " , string (name ))
114
123
}
115
124
continue
116
125
}
@@ -129,7 +138,6 @@ func findDescribes(dir string) ([]string, error) {
129
138
}
130
139
131
140
func createChunkRegexp (numChunks , printChunk int , specs []string ) (string , error ) {
132
-
133
141
numSpecs := len (specs )
134
142
if numSpecs < numChunks {
135
143
return "" , fmt .Errorf ("have more desired chunks (%d) than specs (%d)" , numChunks , numSpecs )
@@ -170,7 +178,6 @@ func createChunkRegexp(numChunks, printChunk int, specs []string) (string, error
170
178
}
171
179
172
180
func findMinimalWordPrefixes (specs []string ) (prefixes []string ) {
173
-
174
181
// Create a word trie of all spec strings.
175
182
t := make (wordTrie )
176
183
for _ , spec := range specs {
0 commit comments