-
Notifications
You must be signed in to change notification settings - Fork 31
/
config.go
99 lines (87 loc) · 2.9 KB
/
config.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
package main
import (
"fmt"
"path"
"strings"
"time"
)
// DefaultBuildOutput - default relative path to watch directory to place built binaries in
const DefaultBuildOutput = "bin/app"
// DefaultCommandArguments - default arguments to pass to commands in the last execution group
const DefaultCommandArguments = ""
// DefaultCommandsDelimiter - default string to split --execs into commands with
const DefaultCommandsDelimiter = ","
// DefaultExecutionGroupsBase - default commands to run when no --execs are specified
var DefaultExecutionGroupsBase = []string{"go mod vendor"}
// DefaultFileExtensions - default commma-separated list of file extensions to watch for
const DefaultFileExtensions = "go,Makefile"
// DefaultIgnoredNames - default comma-separated list of file/dir names to ignore
const DefaultIgnoredNames = "bin,vendor"
// DefaultLogLevel - default log level from 'trace', 'debug', 'info', 'warn', 'error', 'panic'
const DefaultLogLevel = "info"
// DefaultRefreshRate - default duration at which to handle file system events
const DefaultRefreshRate = 2 * time.Second
// Config configures the main application entrypoint
type Config struct {
BuildOutput string
CommandArguments ConfigCommaDelimitedString
CommandsDelimiter string
EnvVars ConfigMultiflagString
ExecGroups ConfigMultiflagString
FileExtensions ConfigCommaDelimitedString
IgnoredNames ConfigCommaDelimitedString
LogLevel LogLevel
LogSilent bool
LogSuperVerbose bool
LogVerbose bool
Rate time.Duration
RunDefault bool
RunInit bool
RunTest bool
RunVersion bool
RunView bool
View string
WatchDirectory string
WorkDirectory string
}
func (config *Config) interpretLogLevel() {
if config.LogVerbose {
config.LogLevel = "debug"
}
if config.LogSuperVerbose {
config.LogLevel = "trace"
}
if config.LogSilent || config.RunVersion || config.RunView {
config.LogLevel = "panic"
}
}
func (config *Config) assignDefaults() {
config.LogLevel = DefaultLogLevel
config.BuildOutput = path.Join(config.WorkDirectory, "/"+config.BuildOutput)
config.RunView = len(config.View) > 0
if len(config.IgnoredNames) == 0 {
config.IgnoredNames = strings.Split(DefaultIgnoredNames, ",")
}
if len(config.FileExtensions) == 0 {
config.FileExtensions = strings.Split(DefaultFileExtensions, ",")
}
if len(config.ExecGroups) == 0 {
if config.RunTest {
testFlags := "-coverprofile c.out"
if config.LogVerbose || config.LogSuperVerbose {
testFlags = fmt.Sprintf("-v %s", testFlags)
}
config.ExecGroups = append(
DefaultExecutionGroupsBase,
fmt.Sprintf("go build -o %s", config.BuildOutput),
fmt.Sprintf("go test ./... %s", testFlags),
)
} else {
config.ExecGroups = append(
DefaultExecutionGroupsBase,
fmt.Sprintf("go build -o %s", config.BuildOutput),
config.BuildOutput,
)
}
}
}