forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.go
64 lines (54 loc) · 1.52 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
package clicommand
import (
"github.com/buildkite/agent/agent"
"github.com/buildkite/agent/logger"
"github.com/codegangsta/cli"
"github.com/oleiade/reflections"
)
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",
}
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)
}
}