-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
51 lines (45 loc) · 904 Bytes
/
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
package mt
import (
"io"
"os"
)
const (
outputTypeNone = iota
outputTypeFormattedTable
outputTypeJSON
)
var cfg = struct {
ContinueOnFailure bool
OutputType int
Stdout io.Writer
WorkingDir string
}{
ContinueOnFailure: false,
OutputType: outputTypeFormattedTable,
Stdout: os.Stdout,
WorkingDir: "",
}
func init() {
if os.Getenv("MELATONIN_CONTINUE_ON_FAILURE") != "" {
cfg.ContinueOnFailure = true
}
cfg.Stdout = os.Stdout
switch os.Getenv("MELATONIN_OUTPUT") {
case "none":
cfg.OutputType = outputTypeNone
cfg.Stdout = io.Discard
case "json":
cfg.OutputType = outputTypeJSON
default:
cfg.OutputType = outputTypeFormattedTable
}
if workdir := os.Getenv("MELATONIN_WORKDIR"); workdir != "" {
cfg.WorkingDir = workdir
} else {
dir, err := os.Getwd()
if err != nil {
panic(err)
}
cfg.WorkingDir = dir
}
}