-
Notifications
You must be signed in to change notification settings - Fork 289
/
global.go
83 lines (71 loc) · 2.01 KB
/
global.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
package clicommand
import (
"github.com/buildkite/agent/agent"
"github.com/buildkite/agent/experiments"
"github.com/buildkite/agent/logger"
"github.com/oleiade/reflections"
"github.com/urfave/cli"
)
const (
DefaultEndpoint = "https://agent.buildkite.com/v3"
)
var AgentAccessTokenFlag = cli.StringFlag{
Name: "agent-access-token",
Value: "",
Usage: "The access token used to identify the agent",
EnvVar: "BUILDKITE_AGENT_ACCESS_TOKEN",
}
var EndpointFlag = cli.StringFlag{
Name: "endpoint",
Value: DefaultEndpoint,
Usage: "The Agent API endpoint",
EnvVar: "BUILDKITE_AGENT_ENDPOINT",
}
var DebugFlag = cli.BoolFlag{
Name: "debug",
Usage: "Enable debug mode",
EnvVar: "BUILDKITE_AGENT_DEBUG",
}
var DebugHTTPFlag = cli.BoolFlag{
Name: "debug-http",
Usage: "Enable HTTP debug mode, which dumps all request and response bodies to the log",
EnvVar: "BUILDKITE_AGENT_DEBUG_HTTP",
}
var NoColorFlag = cli.BoolFlag{
Name: "no-color",
Usage: "Don't show colors in logging",
EnvVar: "BUILDKITE_AGENT_NO_COLOR",
}
var ExperimentsFlag = cli.StringSliceFlag{
Name: "experiment",
Value: &cli.StringSlice{},
Usage: "Enable experimental features within the buildkite-agent",
EnvVar: "BUILDKITE_AGENT_EXPERIMENT",
}
func HandleGlobalFlags(cfg interface{}) {
// Enable debugging if a Debug option is present
debug, err := reflections.GetField(cfg, "Debug")
if debug == true && err == nil {
logger.SetLevel(logger.DEBUG)
}
// Enable HTTP debugging
debugHTTP, err := reflections.GetField(cfg, "DebugHTTP")
if debugHTTP == true && err == nil {
agent.APIClientEnableHTTPDebug()
}
// Turn off color if a NoColor option is present
noColor, err := reflections.GetField(cfg, "NoColor")
if noColor == true && err == nil {
logger.SetColors(false)
}
// Enable experiments
experimentNames, err := reflections.GetField(cfg, "Experiments")
if err == nil {
experimentNamesSlice, ok := experimentNames.([]string)
if ok {
for _, name := range experimentNamesSlice {
experiments.Enable(name)
}
}
}
}