forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
73 lines (59 loc) · 1.56 KB
/
init.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package convey
import (
"flag"
"os"
"github.com/jtolds/gls"
"github.com/smartystreets/goconvey/convey/reporting"
)
func init() {
declareFlags()
ctxMgr = gls.NewContextManager()
}
func declareFlags() {
flag.BoolVar(&json, "json", false, "When true, emits results in JSON blocks. Default: 'false'")
flag.BoolVar(&silent, "silent", false, "When true, all output from GoConvey is suppressed.")
flag.BoolVar(&story, "story", false, "When true, emits story output, otherwise emits dot output. When not provided, this flag mirros the value of the '-test.v' flag")
if noStoryFlagProvided() {
story = verboseEnabled
}
// FYI: flag.Parse() is called from the testing package.
}
func noStoryFlagProvided() bool {
return !story && !storyDisabled
}
func buildReporter() reporting.Reporter {
switch {
case testReporter != nil:
return testReporter
case json:
return reporting.BuildJsonReporter()
case silent:
return reporting.BuildSilentReporter()
case story:
return reporting.BuildStoryReporter()
default:
return reporting.BuildDotReporter()
}
}
var (
ctxMgr *gls.ContextManager
// only set by internal tests
testReporter reporting.Reporter
)
var (
json bool
silent bool
story bool
verboseEnabled = flagFound("-test.v=true")
storyDisabled = flagFound("-story=false")
)
// flagFound parses the command line args manually for flags defined in other
// packages. Like the '-v' flag from the "testing" package, for instance.
func flagFound(flagValue string) bool {
for _, arg := range os.Args {
if arg == flagValue {
return true
}
}
return false
}