forked from robdimsdale/garagepi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_watch_and_build_command_flags.go
118 lines (99 loc) · 3.46 KB
/
run_watch_and_build_command_flags.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"flag"
"runtime"
"github.com/onsi/ginkgo/config"
)
type RunWatchAndBuildCommandFlags struct {
Recurse bool
Race bool
Cover bool
SkipPackage string
Tags string
//for run and watch commands
NumCPU int
NumCompilers int
ParallelStream bool
Notify bool
AutoNodes bool
//only for run command
KeepGoing bool
UntilItFails bool
RandomizeSuites bool
//only for watch command
Depth int
FlagSet *flag.FlagSet
}
const runMode = 1
const watchMode = 2
const buildMode = 3
func NewRunCommandFlags(flagSet *flag.FlagSet) *RunWatchAndBuildCommandFlags {
c := &RunWatchAndBuildCommandFlags{
FlagSet: flagSet,
}
c.flags(runMode)
return c
}
func NewWatchCommandFlags(flagSet *flag.FlagSet) *RunWatchAndBuildCommandFlags {
c := &RunWatchAndBuildCommandFlags{
FlagSet: flagSet,
}
c.flags(watchMode)
return c
}
func NewBuildCommandFlags(flagSet *flag.FlagSet) *RunWatchAndBuildCommandFlags {
c := &RunWatchAndBuildCommandFlags{
FlagSet: flagSet,
}
c.flags(buildMode)
return c
}
func (c *RunWatchAndBuildCommandFlags) wasSet(flagName string) bool {
wasSet := false
c.FlagSet.Visit(func(f *flag.Flag) {
if f.Name == flagName {
wasSet = true
}
})
return wasSet
}
func (c *RunWatchAndBuildCommandFlags) computeNodes() {
if c.wasSet("nodes") {
return
}
if c.AutoNodes {
switch n := runtime.NumCPU(); {
case n <= 4:
c.NumCPU = n
default:
c.NumCPU = n - 1
}
}
}
func (c *RunWatchAndBuildCommandFlags) flags(mode int) {
onWindows := (runtime.GOOS == "windows")
onOSX := (runtime.GOOS == "darwin")
c.FlagSet.BoolVar(&(c.Recurse), "r", false, "Find and run test suites under the current directory recursively")
c.FlagSet.BoolVar(&(c.Race), "race", false, "Run tests with race detection enabled")
c.FlagSet.BoolVar(&(c.Cover), "cover", false, "Run tests with coverage analysis, will generate coverage profiles with the package name in the current directory")
c.FlagSet.StringVar(&(c.SkipPackage), "skipPackage", "", "A comma-separated list of package names to be skipped. If any part of the package's path matches, that package is ignored.")
c.FlagSet.StringVar(&(c.Tags), "tags", "", "A list of build tags to consider satisfied during the build")
if mode == runMode || mode == watchMode {
config.Flags(c.FlagSet, "", false)
c.FlagSet.IntVar(&(c.NumCPU), "nodes", 1, "The number of parallel test nodes to run")
c.FlagSet.IntVar(&(c.NumCompilers), "compilers", 0, "The number of concurrent compilations to run (0 will autodetect)")
c.FlagSet.BoolVar(&(c.AutoNodes), "p", false, "Run in parallel with auto-detected number of nodes")
c.FlagSet.BoolVar(&(c.ParallelStream), "stream", onWindows, "stream parallel test output in real time: less coherent, but useful for debugging")
if onOSX {
c.FlagSet.BoolVar(&(c.Notify), "notify", false, "Send desktop notifications when a test run completes")
}
}
if mode == runMode {
c.FlagSet.BoolVar(&(c.KeepGoing), "keepGoing", false, "When true, failures from earlier test suites do not prevent later test suites from running")
c.FlagSet.BoolVar(&(c.UntilItFails), "untilItFails", false, "When true, Ginkgo will keep rerunning tests until a failure occurs")
c.FlagSet.BoolVar(&(c.RandomizeSuites), "randomizeSuites", false, "When true, Ginkgo will randomize the order in which test suites run")
}
if mode == watchMode {
c.FlagSet.IntVar(&(c.Depth), "depth", 1, "Ginkgo will watch dependencies down to this depth in the dependency tree")
}
}