github.com/stevenmatthewt/agent@v3.5.4+incompatible/clicommand/global.go (about)

     1  package clicommand
     2  
     3  import (
     4  	"github.com/buildkite/agent/agent"
     5  	"github.com/buildkite/agent/experiments"
     6  	"github.com/buildkite/agent/logger"
     7  	"github.com/oleiade/reflections"
     8  	"github.com/urfave/cli"
     9  )
    10  
    11  const (
    12  	DefaultEndpoint = "https://agent.buildkite.com/v3"
    13  )
    14  
    15  var AgentAccessTokenFlag = cli.StringFlag{
    16  	Name:   "agent-access-token",
    17  	Value:  "",
    18  	Usage:  "The access token used to identify the agent",
    19  	EnvVar: "BUILDKITE_AGENT_ACCESS_TOKEN",
    20  }
    21  
    22  var EndpointFlag = cli.StringFlag{
    23  	Name:   "endpoint",
    24  	Value:  DefaultEndpoint,
    25  	Usage:  "The Agent API endpoint",
    26  	EnvVar: "BUILDKITE_AGENT_ENDPOINT",
    27  }
    28  
    29  var DebugFlag = cli.BoolFlag{
    30  	Name:   "debug",
    31  	Usage:  "Enable debug mode",
    32  	EnvVar: "BUILDKITE_AGENT_DEBUG",
    33  }
    34  
    35  var DebugHTTPFlag = cli.BoolFlag{
    36  	Name:   "debug-http",
    37  	Usage:  "Enable HTTP debug mode, which dumps all request and response bodies to the log",
    38  	EnvVar: "BUILDKITE_AGENT_DEBUG_HTTP",
    39  }
    40  
    41  var NoColorFlag = cli.BoolFlag{
    42  	Name:   "no-color",
    43  	Usage:  "Don't show colors in logging",
    44  	EnvVar: "BUILDKITE_AGENT_NO_COLOR",
    45  }
    46  
    47  var ExperimentsFlag = cli.StringSliceFlag{
    48  	Name:   "experiment",
    49  	Value:  &cli.StringSlice{},
    50  	Usage:  "Enable experimental features within the buildkite-agent",
    51  	EnvVar: "BUILDKITE_AGENT_EXPERIMENT",
    52  }
    53  
    54  func HandleGlobalFlags(cfg interface{}) {
    55  	// Enable debugging if a Debug option is present
    56  	debug, err := reflections.GetField(cfg, "Debug")
    57  	if debug == true && err == nil {
    58  		logger.SetLevel(logger.DEBUG)
    59  	}
    60  
    61  	// Enable HTTP debugging
    62  	debugHTTP, err := reflections.GetField(cfg, "DebugHTTP")
    63  	if debugHTTP == true && err == nil {
    64  		agent.APIClientEnableHTTPDebug()
    65  	}
    66  
    67  	// Turn off color if a NoColor option is present
    68  	noColor, err := reflections.GetField(cfg, "NoColor")
    69  	if noColor == true && err == nil {
    70  		logger.SetColors(false)
    71  	}
    72  
    73  	// Enable experiments
    74  	experimentNames, err := reflections.GetField(cfg, "Experiments")
    75  	if err == nil {
    76  		experimentNamesSlice, ok := experimentNames.([]string)
    77  		if ok {
    78  			for _, name := range experimentNamesSlice {
    79  				experiments.Enable(name)
    80  			}
    81  		}
    82  	}
    83  }