diff --git a/bootstrap/integration/main_test.go b/bootstrap/integration/main_test.go index 4d9b8dcc09..bf3b55915b 100644 --- a/bootstrap/integration/main_test.go +++ b/bootstrap/integration/main_test.go @@ -9,7 +9,7 @@ import ( "github.com/buildkite/agent/v3/clicommand" "github.com/buildkite/agent/v3/experiments" "github.com/buildkite/bintest" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) func TestMain(m *testing.M) { @@ -18,8 +18,8 @@ func TestMain(m *testing.M) { app := cli.NewApp() app.Name = "buildkite-agent" app.Version = agent.Version() - app.Commands = []*cli.Command{ - &clicommand.BootstrapCommand, + app.Commands = []cli.Command{ + clicommand.BootstrapCommand, } if err := app.Run(os.Args); err != nil { diff --git a/clicommand/agent_start.go b/clicommand/agent_start.go index 1401323bb6..083969d910 100644 --- a/clicommand/agent_start.go +++ b/clicommand/agent_start.go @@ -18,7 +18,7 @@ import ( "github.com/buildkite/agent/v3/metrics" "github.com/buildkite/agent/v3/process" "github.com/buildkite/shellwords" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var StartDescription = `Usage: @@ -156,250 +156,249 @@ var AgentStartCommand = cli.Command{ Usage: "Starts a Buildkite agent", Description: StartDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "config", - Value: "", - Usage: "Path to a configuration file", - EnvVars: []string{"BUILDKITE_AGENT_CONFIG"}, - }, - &cli.StringFlag{ - Name: "name", - Value: "", - Usage: "The name of the agent", - EnvVars: []string{"BUILDKITE_AGENT_NAME"}, - }, - &cli.StringFlag{ - Name: "priority", - Value: "", - Usage: "The priority of the agent (higher priorities are assigned work first)", - EnvVars: []string{"BUILDKITE_AGENT_PRIORITY"}, - }, - &cli.StringFlag{ - Name: "acquire-job", - Value: "", - Usage: "Start this agent and only run the specified job, disconnecting after it's finished", - EnvVars: []string{"BUILDKITE_AGENT_ACQUIRE_JOB"}, - }, - &cli.BoolFlag{ - Name: "disconnect-after-job", - Usage: "Disconnect the agent after running a job", - EnvVars: []string{"BUILDKITE_AGENT_DISCONNECT_AFTER_JOB"}, - }, - &cli.IntFlag{ - Name: "disconnect-after-idle-timeout", - Value: 0, - Usage: "If no jobs have come in for the specified number of seconds, disconnect the agent", - EnvVars: []string{"BUILDKITE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT"}, - }, - &cli.IntFlag{ - Name: "cancel-grace-period", - Value: 10, - Usage: "The number of seconds a canceled or timed out job is given to gracefully terminate and upload its artifacts", - EnvVars: []string{"BUILDKITE_CANCEL_GRACE_PERIOD"}, - }, - &cli.StringFlag{ - Name: "shell", - Value: DefaultShell(), - Usage: "The shell command used to interpret build commands, e.g /bin/bash -e -c", - EnvVars: []string{"BUILDKITE_SHELL"}, - }, - &cli.StringSliceFlag{ - Name: "tags", - Value: &cli.StringSlice{}, - Usage: "A comma-separated list of tags for the agent (e.g. \"linux\" or \"mac,xcode=8\")", - EnvVars: []string{"BUILDKITE_AGENT_TAGS"}, - }, - &cli.BoolFlag{ - Name: "tags-from-host", - Usage: "Include tags from the host (hostname, machine-id, os)", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_HOST"}, - }, - &cli.StringSliceFlag{ - Name: "tags-from-ec2-meta-data", - Value: &cli.StringSlice{}, - Usage: "Include the default set of host EC2 meta-data as tags (instance-id, instance-type, and ami-id)", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_EC2_META_DATA"}, - }, - &cli.StringSliceFlag{ - Name: "tags-from-ec2-meta-data-paths", - Value: &cli.StringSlice{}, - Usage: "Include additional tags fetched from EC2 meta-data via tag & path suffix pairs, e.g \"tag_name=path/to/value\"", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_EC2_META_DATA_PATHS"}, - }, - &cli.BoolFlag{ - Name: "tags-from-ec2-tags", - Usage: "Include the host's EC2 tags as tags", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_EC2_TAGS"}, - }, - &cli.StringSliceFlag{ - Name: "tags-from-gcp-meta-data", - Value: &cli.StringSlice{}, - Usage: "Include the default set of host Google Cloud instance meta-data as tags (instance-id, machine-type, preemptible, project-id, region, and zone)", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_GCP_META_DATA"}, - }, - &cli.StringSliceFlag{ - Name: "tags-from-gcp-meta-data-paths", - Value: &cli.StringSlice{}, - Usage: "Include additional tags fetched from Google Cloud instance meta-data via tag & path suffix pairs, e.g \"tag_name=path/to/value\"", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_GCP_META_DATA_PATHS"}, - }, - &cli.BoolFlag{ - Name: "tags-from-gcp-labels", - Usage: "Include the host's Google Cloud instance labels as tags", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_GCP_LABELS"}, - }, - &cli.DurationFlag{ - Name: "wait-for-ec2-tags-timeout", - Usage: "The amount of time to wait for tags from EC2 before proceeding", - EnvVars: []string{"BUILDKITE_AGENT_WAIT_FOR_EC2_TAGS_TIMEOUT"}, - Value: time.Second * 10, - }, - &cli.DurationFlag{ - Name: "wait-for-gcp-labels-timeout", - Usage: "The amount of time to wait for labels from GCP before proceeding", - EnvVars: []string{"BUILDKITE_AGENT_WAIT_FOR_GCP_LABELS_TIMEOUT"}, - Value: time.Second * 10, - }, - &cli.StringFlag{ - Name: "git-clone-flags", - Value: "-v", - Usage: "Flags to pass to the \"git clone\" command", - EnvVars: []string{"BUILDKITE_GIT_CLONE_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-clean-flags", - Value: "-ffxdq", - Usage: "Flags to pass to \"git clean\" command", - EnvVars: []string{"BUILDKITE_GIT_CLEAN_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-fetch-flags", - Value: "-v --prune", - Usage: "Flags to pass to \"git fetch\" command", - EnvVars: []string{"BUILDKITE_GIT_FETCH_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-clone-mirror-flags", - Value: "-v --mirror", - Usage: "Flags to pass to the \"git clone\" command when used for mirroring", - EnvVars: []string{"BUILDKITE_GIT_CLONE_MIRROR_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-mirrors-path", - Value: "", - Usage: "Path to where mirrors of git repositories are stored", - EnvVars: []string{"BUILDKITE_GIT_MIRRORS_PATH"}, - }, - &cli.IntFlag{ - Name: "git-mirrors-lock-timeout", - Value: 300, - Usage: "Seconds to lock a git mirror during clone, should exceed your longest checkout", - EnvVars: []string{"BUILDKITE_GIT_MIRRORS_LOCK_TIMEOUT"}, - }, - &cli.StringFlag{ - Name: "bootstrap-script", - Value: "", - Usage: "The command that is executed for bootstrapping a job, defaults to the bootstrap sub-command of this binary", - EnvVars: []string{"BUILDKITE_BOOTSTRAP_SCRIPT_PATH"}, - }, - &cli.StringFlag{ - Name: "build-path", - Value: "", - Usage: "Path to where the builds will run from", - EnvVars: []string{"BUILDKITE_BUILD_PATH"}, - }, - &cli.StringFlag{ - Name: "hooks-path", - Value: "", - Usage: "Directory where the hook scripts are found", - EnvVars: []string{"BUILDKITE_HOOKS_PATH"}, - }, - &cli.StringFlag{ - Name: "plugins-path", - Value: "", - Usage: "Directory where the plugins are saved to", - EnvVars: []string{"BUILDKITE_PLUGINS_PATH"}, - }, - &cli.BoolFlag{ - Name: "timestamp-lines", - Usage: "Prepend timestamps on each line of output.", - EnvVars: []string{"BUILDKITE_TIMESTAMP_LINES"}, - }, - &cli.StringFlag{ - Name: "health-check-addr", - Usage: "Start an HTTP server on this addr:port that returns whether the agent is healthy, disabled by default", - EnvVars: []string{"BUILDKITE_AGENT_HEALTH_CHECK_ADDR"}, - }, - &cli.BoolFlag{ - Name: "no-pty", - Usage: "Do not run jobs within a pseudo terminal", - EnvVars: []string{"BUILDKITE_NO_PTY"}, - }, - &cli.BoolFlag{ - Name: "no-ssh-keyscan", - Usage: "Don't automatically run ssh-keyscan before checkout", - EnvVars: []string{"BUILDKITE_NO_SSH_KEYSCAN"}, - }, - &cli.BoolFlag{ - Name: "no-command-eval", - Usage: "Don't allow this agent to run arbitrary console commands, including plugins", - EnvVars: []string{"BUILDKITE_NO_COMMAND_EVAL"}, - }, - &cli.BoolFlag{ - Name: "no-plugins", - Usage: "Don't allow this agent to load plugins", - EnvVars: []string{"BUILDKITE_NO_PLUGINS"}, - }, - &cli.BoolFlag{ - Name: "no-plugin-validation", - Usage: "Don't validate plugin configuration and requirements", - EnvVars: []string{"BUILDKITE_NO_PLUGIN_VALIDATION"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "no-local-hooks", - Usage: "Don't allow local hooks to be run from checked out repositories", - EnvVars: []string{"BUILDKITE_NO_LOCAL_HOOKS"}, - }, - &cli.BoolFlag{ - Name: "no-git-submodules", - Usage: "Don't automatically checkout git submodules", - EnvVars: []string{"BUILDKITE_NO_GIT_SUBMODULES", "BUILDKITE_DISABLE_GIT_SUBMODULES"}, - }, - &cli.BoolFlag{ - Name: "metrics-datadog", - Usage: "Send metrics to DogStatsD for Datadog", - EnvVars: []string{"BUILDKITE_METRICS_DATADOG"}, - }, - &cli.StringFlag{ - Name: "metrics-datadog-host", - Usage: "The dogstatsd instance to send metrics to via udp", - EnvVars: []string{"BUILDKITE_METRICS_DATADOG_HOST"}, - Value: "127.0.0.1:8125", - }, - &cli.StringFlag{ - Name: "log-format", - Usage: "The format to use for the logger output", - EnvVars: []string{"BUILDKITE_LOG_FORMAT"}, - Value: "text", - }, - &cli.IntFlag{ - Name: "spawn", - Usage: "The number of agents to spawn in parallel", - Value: 1, - EnvVars: []string{"BUILDKITE_AGENT_SPAWN"}, - }, - &cli.StringFlag{ - Name: "cancel-signal", - Usage: "The signal to use for cancellation", - EnvVars: []string{"BUILDKITE_CANCEL_SIGNAL"}, - Value: "SIGTERM", - }, - &cli.StringSliceFlag{ - Name: "redacted-vars", - Usage: "Pattern of environment variable names containing sensitive values", - EnvVars: []string{"BUILDKITE_REDACTED_VARS"}, - Value: cli.NewStringSlice("*_PASSWORD", "*_SECRET", "*_TOKEN"), + cli.StringFlag{ + Name: "config", + Value: "", + Usage: "Path to a configuration file", + EnvVar: "BUILDKITE_AGENT_CONFIG", + }, + cli.StringFlag{ + Name: "name", + Value: "", + Usage: "The name of the agent", + EnvVar: "BUILDKITE_AGENT_NAME", + }, + cli.StringFlag{ + Name: "priority", + Value: "", + Usage: "The priority of the agent (higher priorities are assigned work first)", + EnvVar: "BUILDKITE_AGENT_PRIORITY", + }, + cli.StringFlag{ + Name: "acquire-job", + Value: "", + Usage: "Start this agent and only run the specified job, disconnecting after it's finished", + EnvVar: "BUILDKITE_AGENT_ACQUIRE_JOB", + }, + cli.BoolFlag{ + Name: "disconnect-after-job", + Usage: "Disconnect the agent after running a job", + EnvVar: "BUILDKITE_AGENT_DISCONNECT_AFTER_JOB", + }, + cli.IntFlag{ + Name: "disconnect-after-idle-timeout", + Value: 0, + Usage: "If no jobs have come in for the specified number of seconds, disconnect the agent", + EnvVar: "BUILDKITE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT", + }, + cli.IntFlag{ + Name: "cancel-grace-period", + Value: 10, + Usage: "The number of seconds a canceled or timed out job is given to gracefully terminate and upload its artifacts", + EnvVar: "BUILDKITE_CANCEL_GRACE_PERIOD", + }, + cli.StringFlag{ + Name: "shell", + Value: DefaultShell(), + Usage: "The shell command used to interpret build commands, e.g /bin/bash -e -c", + EnvVar: "BUILDKITE_SHELL", + }, + cli.StringSliceFlag{ + Name: "tags", + Value: &cli.StringSlice{}, + Usage: "A comma-separated list of tags for the agent (e.g. \"linux\" or \"mac,xcode=8\")", + EnvVar: "BUILDKITE_AGENT_TAGS", + }, + cli.BoolFlag{ + Name: "tags-from-host", + Usage: "Include tags from the host (hostname, machine-id, os)", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_HOST", + }, + cli.StringSliceFlag{ + Name: "tags-from-ec2-meta-data", + Value: &cli.StringSlice{}, + Usage: "Include the default set of host EC2 meta-data as tags (instance-id, instance-type, and ami-id)", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2_META_DATA", + }, + cli.StringSliceFlag{ + Name: "tags-from-ec2-meta-data-paths", + Value: &cli.StringSlice{}, + Usage: "Include additional tags fetched from EC2 meta-data via tag & path suffix pairs, e.g \"tag_name=path/to/value\"", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2_META_DATA_PATHS", + }, + cli.BoolFlag{ + Name: "tags-from-ec2-tags", + Usage: "Include the host's EC2 tags as tags", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2_TAGS", + }, + cli.StringSliceFlag{ + Name: "tags-from-gcp-meta-data", + Value: &cli.StringSlice{}, + Usage: "Include the default set of host Google Cloud instance meta-data as tags (instance-id, machine-type, preemptible, project-id, region, and zone)", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_GCP_META_DATA", + }, + cli.StringSliceFlag{ + Name: "tags-from-gcp-meta-data-paths", + Value: &cli.StringSlice{}, + Usage: "Include additional tags fetched from Google Cloud instance meta-data via tag & path suffix pairs, e.g \"tag_name=path/to/value\"", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_GCP_META_DATA_PATHS", + }, + cli.BoolFlag{ + Name: "tags-from-gcp-labels", + Usage: "Include the host's Google Cloud instance labels as tags", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_GCP_LABELS", + }, + cli.DurationFlag{ + Name: "wait-for-ec2-tags-timeout", + Usage: "The amount of time to wait for tags from EC2 before proceeding", + EnvVar: "BUILDKITE_AGENT_WAIT_FOR_EC2_TAGS_TIMEOUT", + Value: time.Second * 10, + }, + cli.DurationFlag{ + Name: "wait-for-gcp-labels-timeout", + Usage: "The amount of time to wait for labels from GCP before proceeding", + EnvVar: "BUILDKITE_AGENT_WAIT_FOR_GCP_LABELS_TIMEOUT", + Value: time.Second * 10, + }, + cli.StringFlag{ + Name: "git-clone-flags", + Value: "-v", + Usage: "Flags to pass to the \"git clone\" command", + EnvVar: "BUILDKITE_GIT_CLONE_FLAGS", + }, + cli.StringFlag{ + Name: "git-clean-flags", + Value: "-ffxdq", + Usage: "Flags to pass to \"git clean\" command", + EnvVar: "BUILDKITE_GIT_CLEAN_FLAGS", + }, + cli.StringFlag{ + Name: "git-fetch-flags", + Value: "-v --prune", + Usage: "Flags to pass to \"git fetch\" command", + EnvVar: "BUILDKITE_GIT_FETCH_FLAGS", + }, + cli.StringFlag{ + Name: "git-clone-mirror-flags", + Value: "-v --mirror", + Usage: "Flags to pass to the \"git clone\" command when used for mirroring", + EnvVar: "BUILDKITE_GIT_CLONE_MIRROR_FLAGS", + }, + cli.StringFlag{ + Name: "git-mirrors-path", + Value: "", + Usage: "Path to where mirrors of git repositories are stored", + EnvVar: "BUILDKITE_GIT_MIRRORS_PATH", + }, + cli.IntFlag{ + Name: "git-mirrors-lock-timeout", + Value: 300, + Usage: "Seconds to lock a git mirror during clone, should exceed your longest checkout", + EnvVar: "BUILDKITE_GIT_MIRRORS_LOCK_TIMEOUT", + }, + cli.StringFlag{ + Name: "bootstrap-script", + Value: "", + Usage: "The command that is executed for bootstrapping a job, defaults to the bootstrap sub-command of this binary", + EnvVar: "BUILDKITE_BOOTSTRAP_SCRIPT_PATH", + }, + cli.StringFlag{ + Name: "build-path", + Value: "", + Usage: "Path to where the builds will run from", + EnvVar: "BUILDKITE_BUILD_PATH", + }, + cli.StringFlag{ + Name: "hooks-path", + Value: "", + Usage: "Directory where the hook scripts are found", + EnvVar: "BUILDKITE_HOOKS_PATH", + }, + cli.StringFlag{ + Name: "plugins-path", + Value: "", + Usage: "Directory where the plugins are saved to", + EnvVar: "BUILDKITE_PLUGINS_PATH", + }, + cli.BoolFlag{ + Name: "timestamp-lines", + Usage: "Prepend timestamps on each line of output.", + EnvVar: "BUILDKITE_TIMESTAMP_LINES", + }, + cli.StringFlag{ + Name: "health-check-addr", + Usage: "Start an HTTP server on this addr:port that returns whether the agent is healthy, disabled by default", + EnvVar: "BUILDKITE_AGENT_HEALTH_CHECK_ADDR", + }, + cli.BoolFlag{ + Name: "no-pty", + Usage: "Do not run jobs within a pseudo terminal", + EnvVar: "BUILDKITE_NO_PTY", + }, + cli.BoolFlag{ + Name: "no-ssh-keyscan", + Usage: "Don't automatically run ssh-keyscan before checkout", + EnvVar: "BUILDKITE_NO_SSH_KEYSCAN", + }, + cli.BoolFlag{ + Name: "no-command-eval", + Usage: "Don't allow this agent to run arbitrary console commands, including plugins", + EnvVar: "BUILDKITE_NO_COMMAND_EVAL", + }, + cli.BoolFlag{ + Name: "no-plugins", + Usage: "Don't allow this agent to load plugins", + EnvVar: "BUILDKITE_NO_PLUGINS", + }, + cli.BoolTFlag{ + Name: "no-plugin-validation", + Usage: "Don't validate plugin configuration and requirements", + EnvVar: "BUILDKITE_NO_PLUGIN_VALIDATION", + }, + cli.BoolFlag{ + Name: "no-local-hooks", + Usage: "Don't allow local hooks to be run from checked out repositories", + EnvVar: "BUILDKITE_NO_LOCAL_HOOKS", + }, + cli.BoolFlag{ + Name: "no-git-submodules", + Usage: "Don't automatically checkout git submodules", + EnvVar: "BUILDKITE_NO_GIT_SUBMODULES,BUILDKITE_DISABLE_GIT_SUBMODULES", + }, + cli.BoolFlag{ + Name: "metrics-datadog", + Usage: "Send metrics to DogStatsD for Datadog", + EnvVar: "BUILDKITE_METRICS_DATADOG", + }, + cli.StringFlag{ + Name: "metrics-datadog-host", + Usage: "The dogstatsd instance to send metrics to via udp", + EnvVar: "BUILDKITE_METRICS_DATADOG_HOST", + Value: "127.0.0.1:8125", + }, + cli.StringFlag{ + Name: "log-format", + Usage: "The format to use for the logger output", + EnvVar: "BUILDKITE_LOG_FORMAT", + Value: "text", + }, + cli.IntFlag{ + Name: "spawn", + Usage: "The number of agents to spawn in parallel", + Value: 1, + EnvVar: "BUILDKITE_AGENT_SPAWN", + }, + cli.StringFlag{ + Name: "cancel-signal", + Usage: "The signal to use for cancellation", + EnvVar: "BUILDKITE_CANCEL_SIGNAL", + Value: "SIGTERM", + }, + cli.StringSliceFlag{ + Name: "redacted-vars", + Usage: "Pattern of environment variable names containing sensitive values", + EnvVar: "BUILDKITE_REDACTED_VARS", + Value: &cli.StringSlice{"*_PASSWORD", "*_SECRET", "*_TOKEN"}, }, // API Flags @@ -415,50 +414,50 @@ var AgentStartCommand = cli.Command{ ProfileFlag, // Deprecated flags which will be removed in v4 - &cli.StringSliceFlag{ - Name: "meta-data", - Value: &cli.StringSlice{}, - Hidden: true, - EnvVars: []string{"BUILDKITE_AGENT_META_DATA"}, - }, - &cli.BoolFlag{ - Name: "meta-data-ec2", - Hidden: true, - EnvVars: []string{"BUILDKITE_AGENT_META_DATA_EC2"}, - }, - &cli.BoolFlag{ - Name: "meta-data-ec2-tags", - Hidden: true, - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_EC2_TAGS"}, - }, - &cli.BoolFlag{ - Name: "meta-data-gcp", - Hidden: true, - EnvVars: []string{"BUILDKITE_AGENT_META_DATA_GCP"}, - }, - &cli.BoolFlag{ - Name: "no-automatic-ssh-fingerprint-verification", - Hidden: true, - EnvVars: []string{"BUILDKITE_NO_AUTOMATIC_SSH_FINGERPRINT_VERIFICATION"}, - }, - &cli.BoolFlag{ - Name: "tags-from-ec2", - Usage: "Include the host's EC2 meta-data as tags (instance-id, instance-type, and ami-id)", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_EC2"}, - }, - &cli.BoolFlag{ - Name: "tags-from-gcp", - Usage: "Include the host's Google Cloud instance meta-data as tags (instance-id, machine-type, preemptible, project-id, region, and zone)", - EnvVars: []string{"BUILDKITE_AGENT_TAGS_FROM_GCP"}, - }, - &cli.IntFlag{ - Name: "disconnect-after-job-timeout", - Hidden: true, - Usage: "When --disconnect-after-job is specified, the number of seconds to wait for a job before shutting down", - EnvVars: []string{"BUILDKITE_AGENT_DISCONNECT_AFTER_JOB_TIMEOUT"}, + cli.StringSliceFlag{ + Name: "meta-data", + Value: &cli.StringSlice{}, + Hidden: true, + EnvVar: "BUILDKITE_AGENT_META_DATA", + }, + cli.BoolFlag{ + Name: "meta-data-ec2", + Hidden: true, + EnvVar: "BUILDKITE_AGENT_META_DATA_EC2", + }, + cli.BoolFlag{ + Name: "meta-data-ec2-tags", + Hidden: true, + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2_TAGS", + }, + cli.BoolFlag{ + Name: "meta-data-gcp", + Hidden: true, + EnvVar: "BUILDKITE_AGENT_META_DATA_GCP", + }, + cli.BoolFlag{ + Name: "no-automatic-ssh-fingerprint-verification", + Hidden: true, + EnvVar: "BUILDKITE_NO_AUTOMATIC_SSH_FINGERPRINT_VERIFICATION", + }, + cli.BoolFlag{ + Name: "tags-from-ec2", + Usage: "Include the host's EC2 meta-data as tags (instance-id, instance-type, and ami-id)", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2", + }, + cli.BoolFlag{ + Name: "tags-from-gcp", + Usage: "Include the host's Google Cloud instance meta-data as tags (instance-id, machine-type, preemptible, project-id, region, and zone)", + EnvVar: "BUILDKITE_AGENT_TAGS_FROM_GCP", + }, + cli.IntFlag{ + Name: "disconnect-after-job-timeout", + Hidden: true, + Usage: "When --disconnect-after-job is specified, the number of seconds to wait for a job before shutting down", + EnvVar: "BUILDKITE_AGENT_DISCONNECT_AFTER_JOB_TIMEOUT", }, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := AgentStartConfig{} @@ -751,7 +750,6 @@ var AgentStartCommand = cli.Command{ if err := pool.Start(); err != nil { l.Fatal("%s", err) } - return nil }, } diff --git a/clicommand/annotate.go b/clicommand/annotate.go index e0d879a68a..3bddc8b8d1 100644 --- a/clicommand/annotate.go +++ b/clicommand/annotate.go @@ -10,7 +10,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var AnnotateHelpDescription = `Usage: @@ -72,26 +72,26 @@ var AnnotateCommand = cli.Command{ Usage: "Annotate the build page within the Buildkite UI with text from within a Buildkite job", Description: AnnotateHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "context", - Usage: "The context of the annotation used to differentiate this annotation from others", - EnvVars: []string{"BUILDKITE_ANNOTATION_CONTEXT"}, + cli.StringFlag{ + Name: "context", + Usage: "The context of the annotation used to differentiate this annotation from others", + EnvVar: "BUILDKITE_ANNOTATION_CONTEXT", }, - &cli.StringFlag{ - Name: "style", - Usage: "The style of the annotation (`success`, `info`, `warning` or `error`)", - EnvVars: []string{"BUILDKITE_ANNOTATION_STYLE"}, + cli.StringFlag{ + Name: "style", + Usage: "The style of the annotation (`success`, `info`, `warning` or `error`)", + EnvVar: "BUILDKITE_ANNOTATION_STYLE", }, - &cli.BoolFlag{ - Name: "append", - Usage: "Append to the body of an existing annotation", - EnvVars: []string{"BUILDKITE_ANNOTATION_APPEND"}, + cli.BoolFlag{ + Name: "append", + Usage: "Append to the body of an existing annotation", + EnvVar: "BUILDKITE_ANNOTATION_APPEND", }, - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "Which job should the annotation come from", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "Which job should the annotation come from", + EnvVar: "BUILDKITE_JOB_ID", }, // API Flags @@ -106,7 +106,7 @@ var AnnotateCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := AnnotateConfig{} @@ -174,6 +174,5 @@ var AnnotateCommand = cli.Command{ } l.Debug("Successfully annotated build") - return nil }, } diff --git a/clicommand/artifact_download.go b/clicommand/artifact_download.go index bea20847cd..1584644204 100644 --- a/clicommand/artifact_download.go +++ b/clicommand/artifact_download.go @@ -4,7 +4,7 @@ import ( "github.com/buildkite/agent/v3/agent" "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var DownloadHelpDescription = `Usage: @@ -59,21 +59,21 @@ var ArtifactDownloadCommand = cli.Command{ Usage: "Downloads artifacts from Buildkite to the local machine", Description: DownloadHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ + cli.StringFlag{ Name: "step", Value: "", Usage: "Scope the search to a particular step by using either its name or job ID", }, - &cli.StringFlag{ - Name: "build", - Value: "", - EnvVars: []string{"BUILDKITE_BUILD_ID"}, - Usage: "The build that the artifacts were uploaded to", + cli.StringFlag{ + Name: "build", + Value: "", + EnvVar: "BUILDKITE_BUILD_ID", + Usage: "The build that the artifacts were uploaded to", }, - &cli.BoolFlag{ - Name: "include-retried-jobs", - EnvVars: []string{"BUILDKITE_AGENT_INCLUDE_RETRIED_JOBS"}, - Usage: "Include artifacts from retried jobs in the search", + cli.BoolFlag{ + Name: "include-retried-jobs", + EnvVar: "BUILDKITE_AGENT_INCLUDE_RETRIED_JOBS", + Usage: "Include artifacts from retried jobs in the search", }, // API Flags @@ -88,7 +88,7 @@ var ArtifactDownloadCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := ArtifactDownloadConfig{} @@ -120,7 +120,5 @@ var ArtifactDownloadCommand = cli.Command{ if err := downloader.Download(); err != nil { l.Fatal("Failed to download artifacts: %s", err) } - - return nil }, } diff --git a/clicommand/artifact_search.go b/clicommand/artifact_search.go index e47385603e..c2eb5e3f9a 100644 --- a/clicommand/artifact_search.go +++ b/clicommand/artifact_search.go @@ -9,7 +9,7 @@ import ( "github.com/buildkite/agent/v3/agent" "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var SearchHelpDescription = `Usage: @@ -69,23 +69,23 @@ var ArtifactSearchCommand = cli.Command{ Usage: "Searches artifacts in Buildkite", Description: SearchHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ + cli.StringFlag{ Name: "step", Value: "", Usage: "Scope the search to a particular step by using either its name or job ID", }, - &cli.StringFlag{ + cli.StringFlag{ Name: "build", Value: "", - EnvVars: []string{"BUILDKITE_BUILD_ID"}, + EnvVar: "BUILDKITE_BUILD_ID", Usage: "The build that the artifacts were uploaded to", }, - &cli.BoolFlag{ + cli.BoolFlag{ Name: "include-retried-jobs", - EnvVars: []string{"BUILDKITE_AGENT_INCLUDE_RETRIED_JOBS"}, + EnvVar: "BUILDKITE_AGENT_INCLUDE_RETRIED_JOBS", Usage: "Include artifacts from retried jobs in the search", }, - &cli.StringFlag{ + cli.StringFlag{ Name: "format", Value: "%j %p %c\n", Usage: `Output formatting of results. Defaults to "%j %p %c\n" (Job ID, path, created at time). @@ -146,7 +146,7 @@ var ArtifactSearchCommand = cli.Command{ } if len(artifacts) == 0 { - return cli.Exit(fmt.Sprintf("No matches found for %q", cfg.Query), 1) + l.Fatal(fmt.Sprintf("No matches found for %q", cfg.Query)) } for _, artifact := range artifacts { diff --git a/clicommand/artifact_shasum.go b/clicommand/artifact_shasum.go index 2d4072767c..b0791f9648 100644 --- a/clicommand/artifact_shasum.go +++ b/clicommand/artifact_shasum.go @@ -6,7 +6,7 @@ import ( "github.com/buildkite/agent/v3/agent" "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var ShasumHelpDescription = `Usage: @@ -60,21 +60,21 @@ var ArtifactShasumCommand = cli.Command{ Usage: "Prints the SHA-1 checksum for the artifact provided to STDOUT", Description: ShasumHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ + cli.StringFlag{ Name: "step", Value: "", Usage: "Scope the search to a particular step by using either its name of job ID", }, - &cli.StringFlag{ - Name: "build", - Value: "", - EnvVars: []string{"BUILDKITE_BUILD_ID"}, - Usage: "The build that the artifacts were uploaded to", + cli.StringFlag{ + Name: "build", + Value: "", + EnvVar: "BUILDKITE_BUILD_ID", + Usage: "The build that the artifacts were uploaded to", }, - &cli.BoolFlag{ - Name: "include-retried-jobs", - EnvVars: []string{"BUILDKITE_AGENT_INCLUDE_RETRIED_JOBS"}, - Usage: "Include artifacts from retried jobs in the search", + cli.BoolFlag{ + Name: "include-retried-jobs", + EnvVar: "BUILDKITE_AGENT_INCLUDE_RETRIED_JOBS", + Usage: "Include artifacts from retried jobs in the search", }, // API Flags @@ -89,7 +89,7 @@ var ArtifactShasumCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := ArtifactShasumConfig{} @@ -126,7 +126,5 @@ var ArtifactShasumCommand = cli.Command{ fmt.Printf("%s\n", artifacts[0].Sha1Sum) } - - return nil }, } diff --git a/clicommand/artifact_upload.go b/clicommand/artifact_upload.go index aa7a72016e..3207d7346d 100644 --- a/clicommand/artifact_upload.go +++ b/clicommand/artifact_upload.go @@ -4,7 +4,7 @@ import ( "github.com/buildkite/agent/v3/agent" "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var UploadHelpDescription = `Usage: @@ -73,17 +73,17 @@ var ArtifactUploadCommand = cli.Command{ Usage: "Uploads files to a job as artifacts", Description: UploadHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "Which job should the artifacts be uploaded to", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "Which job should the artifacts be uploaded to", + EnvVar: "BUILDKITE_JOB_ID", }, - &cli.StringFlag{ - Name: "content-type", - Value: "", - Usage: "A specific Content-Type to set for the artifacts (otherwise detected)", - EnvVars: []string{"BUILDKITE_ARTIFACT_CONTENT_TYPE"}, + cli.StringFlag{ + Name: "content-type", + Value: "", + Usage: "A specific Content-Type to set for the artifacts (otherwise detected)", + EnvVar: "BUILDKITE_ARTIFACT_CONTENT_TYPE", }, // API Flags @@ -98,7 +98,7 @@ var ArtifactUploadCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := ArtifactUploadConfig{} @@ -129,7 +129,5 @@ var ArtifactUploadCommand = cli.Command{ if err := uploader.Upload(); err != nil { l.Fatal("Failed to upload artifacts: %s", err) } - - return nil }, } diff --git a/clicommand/bootstrap.go b/clicommand/bootstrap.go index 694ac61d44..d3f7c7852b 100644 --- a/clicommand/bootstrap.go +++ b/clicommand/bootstrap.go @@ -12,7 +12,7 @@ import ( "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/experiments" "github.com/buildkite/agent/v3/logger" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var BootstrapHelpDescription = `Usage: @@ -88,224 +88,217 @@ var BootstrapCommand = cli.Command{ Usage: "Run a Buildkite job locally", Description: BootstrapHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "command", - Value: "", - Usage: "The command to run", - EnvVars: []string{"BUILDKITE_COMMAND"}, - }, - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "The ID of the job being run", - EnvVars: []string{"BUILDKITE_JOB_ID"}, - }, - &cli.StringFlag{ - Name: "repository", - Value: "", - Usage: "The repository to clone and run the job from", - EnvVars: []string{"BUILDKITE_REPO"}, - }, - &cli.StringFlag{ - Name: "commit", - Value: "", - Usage: "The commit to checkout in the repository", - EnvVars: []string{"BUILDKITE_COMMIT"}, - }, - &cli.StringFlag{ - Name: "branch", - Value: "", - Usage: "The branch the commit is in", - EnvVars: []string{"BUILDKITE_BRANCH"}, - }, - &cli.StringFlag{ - Name: "tag", - Value: "", - Usage: "The tag the commit", - EnvVars: []string{"BUILDKITE_TAG"}, - }, - &cli.StringFlag{ - Name: "refspec", - Value: "", - Usage: "Optional refspec to override git fetch", - EnvVars: []string{"BUILDKITE_REFSPEC"}, - }, - &cli.StringFlag{ - Name: "plugins", - Value: "", - Usage: "The plugins for the job", - EnvVars: []string{"BUILDKITE_PLUGINS"}, - }, - &cli.StringFlag{ - Name: "pullrequest", - Value: "", - Usage: "The number/id of the pull request this commit belonged to", - EnvVars: []string{"BUILDKITE_PULL_REQUEST"}, - }, - &cli.StringFlag{ - Name: "agent", - Value: "", - Usage: "The name of the agent running the job", - EnvVars: []string{"BUILDKITE_AGENT_NAME"}, - }, - &cli.StringFlag{ - Name: "organization", - Value: "", - Usage: "The slug of the organization that the job is a part of", - EnvVars: []string{"BUILDKITE_ORGANIZATION_SLUG"}, - }, - &cli.StringFlag{ - Name: "pipeline", - Value: "", - Usage: "The slug of the pipeline that the job is a part of", - EnvVars: []string{"BUILDKITE_PIPELINE_SLUG"}, - }, - &cli.StringFlag{ - Name: "pipeline-provider", - Value: "", - Usage: "The id of the SCM provider that the repository is hosted on", - EnvVars: []string{"BUILDKITE_PIPELINE_PROVIDER"}, - }, - &cli.StringFlag{ - Name: "artifact-upload-paths", - Value: "", - Usage: "Paths to files to automatically upload at the end of a job", - EnvVars: []string{"BUILDKITE_ARTIFACT_PATHS"}, - }, - &cli.StringFlag{ - Name: "artifact-upload-destination", - Value: "", - Usage: "A custom location to upload artifact paths to (i.e. s3://my-custom-bucket)", - EnvVars: []string{"BUILDKITE_ARTIFACT_UPLOAD_DESTINATION"}, - }, - &cli.BoolFlag{ - Name: "clean-checkout", - Usage: "Whether or not the bootstrap should remove the existing repository before running the command", - EnvVars: []string{"BUILDKITE_CLEAN_CHECKOUT"}, - }, - &cli.StringFlag{ - Name: "git-clone-flags", - Value: "-v", - Usage: "Flags to pass to \"git clone\" command", - EnvVars: []string{"BUILDKITE_GIT_CLONE_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-clone-mirror-flags", - Value: "-v --mirror", - Usage: "Flags to pass to \"git clone\" command when mirroring", - EnvVars: []string{"BUILDKITE_GIT_CLONE_MIRROR_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-clean-flags", - Value: "-ffxdq", - Usage: "Flags to pass to \"git clean\" command", - EnvVars: []string{"BUILDKITE_GIT_CLEAN_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-fetch-flags", - Value: "", - Usage: "Flags to pass to \"git fetch\" command", - EnvVars: []string{"BUILDKITE_GIT_FETCH_FLAGS"}, - }, - &cli.StringFlag{ - Name: "git-mirrors-path", - Value: "", - Usage: "Path to where mirrors of git repositories are stored", - EnvVars: []string{"BUILDKITE_GIT_MIRRORS_PATH"}, - }, - &cli.IntFlag{ - Name: "git-mirrors-lock-timeout", - Value: 300, - Usage: "Seconds to lock a git mirror during clone, should exceed your longest checkout", - EnvVars: []string{"BUILDKITE_GIT_MIRRORS_LOCK_TIMEOUT"}, - }, - &cli.StringFlag{ - Name: "bin-path", - Value: "", - Usage: "Directory where the buildkite-agent binary lives", - EnvVars: []string{"BUILDKITE_BIN_PATH"}, - }, - &cli.StringFlag{ - Name: "build-path", - Value: "", - Usage: "Directory where builds will be created", - EnvVars: []string{"BUILDKITE_BUILD_PATH"}, - }, - &cli.StringFlag{ - Name: "hooks-path", - Value: "", - Usage: "Directory where the hook scripts are found", - EnvVars: []string{"BUILDKITE_HOOKS_PATH"}, - }, - &cli.StringFlag{ - Name: "plugins-path", - Value: "", - Usage: "Directory where the plugins are saved to", - EnvVars: []string{"BUILDKITE_PLUGINS_PATH"}, - }, - &cli.BoolFlag{ - Name: "command-eval", - Usage: "Allow running of arbitrary commands", - EnvVars: []string{"BUILDKITE_COMMAND_EVAL"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "plugins-enabled", - Usage: "Allow plugins to be run", - EnvVars: []string{"BUILDKITE_PLUGINS_ENABLED"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "plugin-validation", - Usage: "Validate plugin configuration", - EnvVars: []string{"BUILDKITE_PLUGIN_VALIDATION"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "local-hooks-enabled", - Usage: "Allow local hooks to be run", - EnvVars: []string{"BUILDKITE_LOCAL_HOOKS_ENABLED"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "ssh-keyscan", - Usage: "Automatically run ssh-keyscan before checkout", - EnvVars: []string{"BUILDKITE_SSH_KEYSCAN"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "git-submodules", - Usage: "Enable git submodules", - EnvVars: []string{"BUILDKITE_GIT_SUBMODULES"}, - Value: true, - }, - &cli.BoolFlag{ - Name: "pty", - Usage: "Run jobs within a pseudo terminal", - EnvVars: []string{"BUILDKITE_PTY"}, - Value: true, - }, - &cli.StringFlag{ - Name: "shell", - Usage: "The shell to use to interpret build commands", - EnvVars: []string{"BUILDKITE_SHELL"}, - Value: DefaultShell(), - }, - &cli.StringSliceFlag{ - Name: "phases", - Usage: "The specific phases to execute. The order they're defined is irrelevant.", - EnvVars: []string{"BUILDKITE_BOOTSTRAP_PHASES"}, - }, - &cli.StringSliceFlag{ - Name: "redacted-vars", - Usage: "Pattern of environment variable names containing sensitive values", - EnvVars: []string{"BUILDKITE_REDACTED_VARS"}, + cli.StringFlag{ + Name: "command", + Value: "", + Usage: "The command to run", + EnvVar: "BUILDKITE_COMMAND", + }, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "The ID of the job being run", + EnvVar: "BUILDKITE_JOB_ID", + }, + cli.StringFlag{ + Name: "repository", + Value: "", + Usage: "The repository to clone and run the job from", + EnvVar: "BUILDKITE_REPO", + }, + cli.StringFlag{ + Name: "commit", + Value: "", + Usage: "The commit to checkout in the repository", + EnvVar: "BUILDKITE_COMMIT", + }, + cli.StringFlag{ + Name: "branch", + Value: "", + Usage: "The branch the commit is in", + EnvVar: "BUILDKITE_BRANCH", + }, + cli.StringFlag{ + Name: "tag", + Value: "", + Usage: "The tag the commit", + EnvVar: "BUILDKITE_TAG", + }, + cli.StringFlag{ + Name: "refspec", + Value: "", + Usage: "Optional refspec to override git fetch", + EnvVar: "BUILDKITE_REFSPEC", + }, + cli.StringFlag{ + Name: "plugins", + Value: "", + Usage: "The plugins for the job", + EnvVar: "BUILDKITE_PLUGINS", + }, + cli.StringFlag{ + Name: "pullrequest", + Value: "", + Usage: "The number/id of the pull request this commit belonged to", + EnvVar: "BUILDKITE_PULL_REQUEST", + }, + cli.StringFlag{ + Name: "agent", + Value: "", + Usage: "The name of the agent running the job", + EnvVar: "BUILDKITE_AGENT_NAME", + }, + cli.StringFlag{ + Name: "organization", + Value: "", + Usage: "The slug of the organization that the job is a part of", + EnvVar: "BUILDKITE_ORGANIZATION_SLUG", + }, + cli.StringFlag{ + Name: "pipeline", + Value: "", + Usage: "The slug of the pipeline that the job is a part of", + EnvVar: "BUILDKITE_PIPELINE_SLUG", + }, + cli.StringFlag{ + Name: "pipeline-provider", + Value: "", + Usage: "The id of the SCM provider that the repository is hosted on", + EnvVar: "BUILDKITE_PIPELINE_PROVIDER", + }, + cli.StringFlag{ + Name: "artifact-upload-paths", + Value: "", + Usage: "Paths to files to automatically upload at the end of a job", + EnvVar: "BUILDKITE_ARTIFACT_PATHS", + }, + cli.StringFlag{ + Name: "artifact-upload-destination", + Value: "", + Usage: "A custom location to upload artifact paths to (i.e. s3://my-custom-bucket)", + EnvVar: "BUILDKITE_ARTIFACT_UPLOAD_DESTINATION", + }, + cli.BoolFlag{ + Name: "clean-checkout", + Usage: "Whether or not the bootstrap should remove the existing repository before running the command", + EnvVar: "BUILDKITE_CLEAN_CHECKOUT", + }, + cli.StringFlag{ + Name: "git-clone-flags", + Value: "-v", + Usage: "Flags to pass to \"git clone\" command", + EnvVar: "BUILDKITE_GIT_CLONE_FLAGS", + }, + cli.StringFlag{ + Name: "git-clone-mirror-flags", + Value: "-v --mirror", + Usage: "Flags to pass to \"git clone\" command when mirroring", + EnvVar: "BUILDKITE_GIT_CLONE_MIRROR_FLAGS", + }, + cli.StringFlag{ + Name: "git-clean-flags", + Value: "-ffxdq", + Usage: "Flags to pass to \"git clean\" command", + EnvVar: "BUILDKITE_GIT_CLEAN_FLAGS", + }, + cli.StringFlag{ + Name: "git-fetch-flags", + Value: "", + Usage: "Flags to pass to \"git fetch\" command", + EnvVar: "BUILDKITE_GIT_FETCH_FLAGS", + }, + cli.StringFlag{ + Name: "git-mirrors-path", + Value: "", + Usage: "Path to where mirrors of git repositories are stored", + EnvVar: "BUILDKITE_GIT_MIRRORS_PATH", + }, + cli.IntFlag{ + Name: "git-mirrors-lock-timeout", + Value: 300, + Usage: "Seconds to lock a git mirror during clone, should exceed your longest checkout", + EnvVar: "BUILDKITE_GIT_MIRRORS_LOCK_TIMEOUT", + }, + cli.StringFlag{ + Name: "bin-path", + Value: "", + Usage: "Directory where the buildkite-agent binary lives", + EnvVar: "BUILDKITE_BIN_PATH", + }, + cli.StringFlag{ + Name: "build-path", + Value: "", + Usage: "Directory where builds will be created", + EnvVar: "BUILDKITE_BUILD_PATH", + }, + cli.StringFlag{ + Name: "hooks-path", + Value: "", + Usage: "Directory where the hook scripts are found", + EnvVar: "BUILDKITE_HOOKS_PATH", + }, + cli.StringFlag{ + Name: "plugins-path", + Value: "", + Usage: "Directory where the plugins are saved to", + EnvVar: "BUILDKITE_PLUGINS_PATH", + }, + cli.BoolTFlag{ + Name: "command-eval", + Usage: "Allow running of arbitrary commands", + EnvVar: "BUILDKITE_COMMAND_EVAL", + }, + cli.BoolTFlag{ + Name: "plugins-enabled", + Usage: "Allow plugins to be run", + EnvVar: "BUILDKITE_PLUGINS_ENABLED", + }, + cli.BoolFlag{ + Name: "plugin-validation", + Usage: "Validate plugin configuration", + EnvVar: "BUILDKITE_PLUGIN_VALIDATION", + }, + cli.BoolTFlag{ + Name: "local-hooks-enabled", + Usage: "Allow local hooks to be run", + EnvVar: "BUILDKITE_LOCAL_HOOKS_ENABLED", + }, + cli.BoolTFlag{ + Name: "ssh-keyscan", + Usage: "Automatically run ssh-keyscan before checkout", + EnvVar: "BUILDKITE_SSH_KEYSCAN", + }, + cli.BoolTFlag{ + Name: "git-submodules", + Usage: "Enable git submodules", + EnvVar: "BUILDKITE_GIT_SUBMODULES", + }, + cli.BoolTFlag{ + Name: "pty", + Usage: "Run jobs within a pseudo terminal", + EnvVar: "BUILDKITE_PTY", + }, + cli.StringFlag{ + Name: "shell", + Usage: "The shell to use to interpret build commands", + EnvVar: "BUILDKITE_SHELL", + Value: DefaultShell(), + }, + cli.StringSliceFlag{ + Name: "phases", + Usage: "The specific phases to execute. The order they're defined is irrelevant.", + EnvVar: "BUILDKITE_BOOTSTRAP_PHASES", + }, + cli.StringSliceFlag{ + Name: "redacted-vars", + Usage: "Pattern of environment variable names containing sensitive values", + EnvVar: "BUILDKITE_REDACTED_VARS", }, DebugFlag, ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := BootstrapConfig{} @@ -443,7 +436,5 @@ var BootstrapCommand = cli.Command{ } os.Exit(exitCode) - - return nil }, } diff --git a/clicommand/global.go b/clicommand/global.go index 1bd3eaf813..e5f769d4f8 100644 --- a/clicommand/global.go +++ b/clicommand/global.go @@ -5,75 +5,76 @@ import ( "fmt" "os" "reflect" + "strings" "github.com/buildkite/agent/v3/agent" "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/experiments" "github.com/buildkite/agent/v3/logger" "github.com/oleiade/reflections" - "github.com/urfave/cli/v2" + "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", - EnvVars: []string{"BUILDKITE_AGENT_ACCESS_TOKEN"}, +var AgentAccessTokenFlag = cli.StringFlag{ + Name: "agent-access-token", + Value: "", + Usage: "The access token used to identify the agent", + EnvVar: "BUILDKITE_AGENT_ACCESS_TOKEN", } -var AgentRegisterTokenFlag = &cli.StringFlag{ - Name: "token", - Value: "", - Usage: "Your account agent token", - EnvVars: []string{"BUILDKITE_AGENT_TOKEN"}, +var AgentRegisterTokenFlag = cli.StringFlag{ + Name: "token", + Value: "", + Usage: "Your account agent token", + EnvVar: "BUILDKITE_AGENT_TOKEN", } -var EndpointFlag = &cli.StringFlag{ - Name: "endpoint", - Value: DefaultEndpoint, - Usage: "The Agent API endpoint", - EnvVars: []string{"BUILDKITE_AGENT_ENDPOINT"}, +var EndpointFlag = cli.StringFlag{ + Name: "endpoint", + Value: DefaultEndpoint, + Usage: "The Agent API endpoint", + EnvVar: "BUILDKITE_AGENT_ENDPOINT", } -var NoHTTP2Flag = &cli.BoolFlag{ - Name: "no-http2", - Usage: "Disable HTTP2 when communicating with the Agent API.", - EnvVars: []string{"BUILDKITE_NO_HTTP2"}, +var NoHTTP2Flag = cli.BoolFlag{ + Name: "no-http2", + Usage: "Disable HTTP2 when communicating with the Agent API.", + EnvVar: "BUILDKITE_NO_HTTP2", } -var DebugFlag = &cli.BoolFlag{ - Name: "debug", - Usage: "Enable debug mode", - EnvVars: []string{"BUILDKITE_AGENT_DEBUG"}, +var DebugFlag = cli.BoolFlag{ + Name: "debug", + Usage: "Enable debug mode", + EnvVar: "BUILDKITE_AGENT_DEBUG", } -var ProfileFlag = &cli.StringFlag{ - Name: "profile", - Usage: "Enable a profiling mode, either cpu, memory, mutex or block", - EnvVars: []string{"BUILDKITE_AGENT_PROFILE"}, +var ProfileFlag = cli.StringFlag{ + Name: "profile", + Usage: "Enable a profiling mode, either cpu, memory, mutex or block", + EnvVar: "BUILDKITE_AGENT_PROFILE", } -var DebugHTTPFlag = &cli.BoolFlag{ - Name: "debug-http", - Usage: "Enable HTTP debug mode, which dumps all request and response bodies to the log", - EnvVars: []string{"BUILDKITE_AGENT_DEBUG_HTTP"}, +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", - EnvVars: []string{"BUILDKITE_AGENT_NO_COLOR"}, +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", - EnvVars: []string{"BUILDKITE_AGENT_EXPERIMENT"}, +var ExperimentsFlag = cli.StringSliceFlag{ + Name: "experiment", + Value: &cli.StringSlice{}, + Usage: "Enable experimental features within the buildkite-agent", + EnvVar: "BUILDKITE_AGENT_EXPERIMENT", } func CreateLogger(cfg interface{}) logger.Logger { @@ -153,20 +154,17 @@ func HandleGlobalFlags(l logger.Logger, cfg interface{}) func() { func UnsetConfigFromEnvironment(c *cli.Context) error { flags := append(c.App.Flags, c.Command.Flags...) for _, fl := range flags { - // use golang reflection to find EnvVars values on flags + // use golang reflection to find EnvVar values on flags r := reflect.ValueOf(fl) - f := reflect.Indirect(r).FieldByName(`EnvVars`) + f := reflect.Indirect(r).FieldByName(`EnvVar`) if !f.IsValid() { - return errors.New("EnvVars field not found on flag") + return errors.New("EnvVar field not found on flag") } - if f.Kind() != reflect.Slice { - return errors.New("EnvVars not a slice") - } - - // Loop over each EnvVar supported by the flag (there can be more than one!) - for i := 0; i < f.Len(); i++ { - envVar := f.Index(i).String() - os.Unsetenv(envVar) + // split comma delimited env + if envVars := f.String(); envVars != `` { + for _, env := range strings.Split(envVars, ",") { + os.Unsetenv(env) + } } } return nil diff --git a/clicommand/meta_data_exists.go b/clicommand/meta_data_exists.go index a7883f0378..4b61ce2e0a 100644 --- a/clicommand/meta_data_exists.go +++ b/clicommand/meta_data_exists.go @@ -7,7 +7,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var MetaDataExistsHelpDescription = `Usage: @@ -45,11 +45,11 @@ var MetaDataExistsCommand = cli.Command{ Usage: "Check to see if the meta data key exists for a build", Description: MetaDataExistsHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "Which job's build should the meta-data be checked for", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "Which job's build should the meta-data be checked for", + EnvVar: "BUILDKITE_JOB_ID", }, // API Flags @@ -64,7 +64,7 @@ var MetaDataExistsCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := MetaDataExistsConfig{} @@ -105,7 +105,5 @@ var MetaDataExistsCommand = cli.Command{ if !exists.Exists { os.Exit(100) } - - return nil }, } diff --git a/clicommand/meta_data_get.go b/clicommand/meta_data_get.go index fed7800d14..a5d3b9a9ad 100644 --- a/clicommand/meta_data_get.go +++ b/clicommand/meta_data_get.go @@ -7,7 +7,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var MetaDataGetHelpDescription = `Usage: @@ -45,16 +45,16 @@ var MetaDataGetCommand = cli.Command{ Usage: "Get data from a build", Description: MetaDataGetHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ + cli.StringFlag{ Name: "default", Value: "", Usage: "If the meta-data value doesn't exist return this instead", }, - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "Which job's build should the meta-data be retrieved from", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "Which job's build should the meta-data be retrieved from", + EnvVar: "BUILDKITE_JOB_ID", }, // API Flags @@ -69,7 +69,7 @@ var MetaDataGetCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := MetaDataGetConfig{} @@ -117,7 +117,7 @@ var MetaDataGetCommand = cli.Command{ l.Warn("No meta-data value exists with key `%s`, returning the supplied default \"%s\"", cfg.Key, cfg.Default) fmt.Print(cfg.Default) - return nil + return } else { l.Fatal("Failed to get meta-data: %s", err) } @@ -125,7 +125,5 @@ var MetaDataGetCommand = cli.Command{ // Output the value to STDOUT fmt.Print(metaData.Value) - - return nil }, } diff --git a/clicommand/meta_data_keys.go b/clicommand/meta_data_keys.go index 34d7763dae..6eb0ce37ba 100644 --- a/clicommand/meta_data_keys.go +++ b/clicommand/meta_data_keys.go @@ -7,7 +7,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var MetaDataKeysHelpDescription = `Usage: @@ -44,11 +44,11 @@ var MetaDataKeysCommand = cli.Command{ Usage: "Lists all meta-data keys that have been previously set", Description: MetaDataKeysHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "Which job's build should the meta-data be checked for", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "Which job's build should the meta-data be checked for", + EnvVar: "BUILDKITE_JOB_ID", }, // API Flags @@ -63,7 +63,7 @@ var MetaDataKeysCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := MetaDataKeysConfig{} @@ -103,7 +103,5 @@ var MetaDataKeysCommand = cli.Command{ for _, key := range keys { fmt.Printf("%s\n", key) } - - return nil }, } diff --git a/clicommand/meta_data_set.go b/clicommand/meta_data_set.go index c79eacb716..0d6e9c2084 100644 --- a/clicommand/meta_data_set.go +++ b/clicommand/meta_data_set.go @@ -8,7 +8,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var MetaDataSetHelpDescription = `Usage: @@ -51,11 +51,11 @@ var MetaDataSetCommand = cli.Command{ Usage: "Set data on a build", Description: MetaDataSetHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "Which job's build should the meta-data be set on", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "Which job's build should the meta-data be set on", + EnvVar: "BUILDKITE_JOB_ID", }, // API Flags @@ -70,7 +70,7 @@ var MetaDataSetCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := MetaDataSetConfig{} @@ -86,7 +86,7 @@ var MetaDataSetCommand = cli.Command{ defer done() // Read the value from STDIN if argument omitted entirely - if c.Args().Len() < 2 { + if len(c.Args()) < 2 { l.Info("Reading meta-data value from STDIN") input, err := ioutil.ReadAll(os.Stdin) @@ -120,7 +120,5 @@ var MetaDataSetCommand = cli.Command{ if err != nil { l.Fatal("Failed to set meta-data: %s", err) } - - return nil }, } diff --git a/clicommand/pipeline_upload.go b/clicommand/pipeline_upload.go index 69fab942f0..46b1114450 100644 --- a/clicommand/pipeline_upload.go +++ b/clicommand/pipeline_upload.go @@ -16,7 +16,7 @@ import ( "github.com/buildkite/agent/v3/env" "github.com/buildkite/agent/v3/retry" "github.com/buildkite/agent/v3/stdin" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var PipelineUploadHelpDescription = `Usage: @@ -73,26 +73,26 @@ var PipelineUploadCommand = cli.Command{ Usage: "Uploads a description of a build pipeline adds it to the currently running build after the current job.", Description: PipelineUploadHelpDescription, Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "replace", - Usage: "Replace the rest of the existing pipeline with the steps uploaded. Jobs that are already running are not removed.", - EnvVars: []string{"BUILDKITE_PIPELINE_REPLACE"}, + cli.BoolFlag{ + Name: "replace", + Usage: "Replace the rest of the existing pipeline with the steps uploaded. Jobs that are already running are not removed.", + EnvVar: "BUILDKITE_PIPELINE_REPLACE", }, - &cli.StringFlag{ - Name: "job", - Value: "", - Usage: "The job that is making the changes to its build", - EnvVars: []string{"BUILDKITE_JOB_ID"}, + cli.StringFlag{ + Name: "job", + Value: "", + Usage: "The job that is making the changes to its build", + EnvVar: "BUILDKITE_JOB_ID", }, - &cli.BoolFlag{ - Name: "dry-run", - Usage: "Rather than uploading the pipeline, it will be echoed to stdout", - EnvVars: []string{"BUILDKITE_PIPELINE_UPLOAD_DRY_RUN"}, + cli.BoolFlag{ + Name: "dry-run", + Usage: "Rather than uploading the pipeline, it will be echoed to stdout", + EnvVar: "BUILDKITE_PIPELINE_UPLOAD_DRY_RUN", }, - &cli.BoolFlag{ - Name: "no-interpolation", - Usage: "Skip variable interpolation the pipeline when uploaded", - EnvVars: []string{"BUILDKITE_PIPELINE_NO_INTERPOLATION"}, + cli.BoolFlag{ + Name: "no-interpolation", + Usage: "Skip variable interpolation the pipeline when uploaded", + EnvVar: "BUILDKITE_PIPELINE_NO_INTERPOLATION", }, // API Flags @@ -107,7 +107,7 @@ var PipelineUploadCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := PipelineUploadConfig{} @@ -233,7 +233,7 @@ var PipelineUploadCommand = cli.Command{ l.Fatal("%#v", err) } - return nil + return } // Check we have a job id set if not in dry run @@ -276,7 +276,5 @@ var PipelineUploadCommand = cli.Command{ } l.Info("Successfully uploaded and parsed pipeline config") - - return nil }, } diff --git a/clicommand/step_get.go b/clicommand/step_get.go index 087aa4b8fc..e5f568d2f8 100644 --- a/clicommand/step_get.go +++ b/clicommand/step_get.go @@ -7,7 +7,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var StepGetHelpDescription = `Usage: @@ -54,23 +54,23 @@ var StepGetCommand = cli.Command{ Usage: "Get the value of an attribute", Description: StepGetHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "step", - Value: "", - Usage: "The step to get. Can be either its ID (BUILDKITE_STEP_ID) or key (BUILDKITE_STEP_KEY)", - EnvVars: []string{"BUILDKITE_STEP_ID"}, + cli.StringFlag{ + Name: "step", + Value: "", + Usage: "The step to get. Can be either its ID (BUILDKITE_STEP_ID) or key (BUILDKITE_STEP_KEY)", + EnvVar: "BUILDKITE_STEP_ID", }, - &cli.StringFlag{ - Name: "build", - Value: "", - Usage: "The build to look for the step in. Only required when targeting a step using its key (BUILDKITE_STEP_KEY)", - EnvVars: []string{"BUILDKITE_BUILD_ID"}, + cli.StringFlag{ + Name: "build", + Value: "", + Usage: "The build to look for the step in. Only required when targeting a step using its key (BUILDKITE_STEP_KEY)", + EnvVar: "BUILDKITE_BUILD_ID", }, - &cli.StringFlag{ - Name: "format", - Value: "", - Usage: "The format to output the attribute value in (currently only JSON is supported)", - EnvVars: []string{"BUILDKITE_STEP_GET_FORMAT"}, + cli.StringFlag{ + Name: "format", + Value: "", + Usage: "The format to output the attribute value in (currently only JSON is supported)", + EnvVar: "BUILDKITE_STEP_GET_FORMAT", }, // API Flags @@ -85,7 +85,7 @@ var StepGetCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := StepGetConfig{} @@ -135,7 +135,5 @@ var StepGetCommand = cli.Command{ // Output the value to STDOUT fmt.Print(stepExportResponse.Output) - - return nil }, } diff --git a/clicommand/step_update.go b/clicommand/step_update.go index b2348b9d16..efc7e7edb8 100644 --- a/clicommand/step_update.go +++ b/clicommand/step_update.go @@ -8,7 +8,7 @@ import ( "github.com/buildkite/agent/v3/api" "github.com/buildkite/agent/v3/cliconfig" "github.com/buildkite/agent/v3/retry" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var StepUpdateHelpDescription = `Usage: @@ -51,22 +51,22 @@ var StepUpdateCommand = cli.Command{ Usage: "Change the value of an attribute", Description: StepUpdateHelpDescription, Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "step", - Value: "", - Usage: "The step to update. Can be either its ID (BUILDKITE_STEP_ID) or key (BUILDKITE_STEP_KEY)", - EnvVars: []string{"BUILDKITE_STEP_ID"}, + cli.StringFlag{ + Name: "step", + Value: "", + Usage: "The step to update. Can be either its ID (BUILDKITE_STEP_ID) or key (BUILDKITE_STEP_KEY)", + EnvVar: "BUILDKITE_STEP_ID", }, - &cli.StringFlag{ - Name: "build", - Value: "", - Usage: "The build to look for the step in. Only required when targeting a step using its key (BUILDKITE_STEP_KEY)", - EnvVars: []string{"BUILDKITE_BUILD_ID"}, + cli.StringFlag{ + Name: "build", + Value: "", + Usage: "The build to look for the step in. Only required when targeting a step using its key (BUILDKITE_STEP_KEY)", + EnvVar: "BUILDKITE_BUILD_ID", }, - &cli.BoolFlag{ - Name: "append", - Usage: "Append to current attribute instead of replacing it", - EnvVars: []string{"BUILDKITE_STEP_UPDATE_APPEND"}, + cli.BoolFlag{ + Name: "append", + Usage: "Append to current attribute instead of replacing it", + EnvVar: "BUILDKITE_STEP_UPDATE_APPEND", }, // API Flags @@ -81,7 +81,7 @@ var StepUpdateCommand = cli.Command{ ExperimentsFlag, ProfileFlag, }, - Action: func(c *cli.Context) error { + Action: func(c *cli.Context) { // The configuration will be loaded into this struct cfg := StepUpdateConfig{} @@ -97,7 +97,7 @@ var StepUpdateCommand = cli.Command{ defer done() // Read the value from STDIN if argument omitted entirely - if c.Args().Len() < 2 { + if len(c.Args()) < 2 { l.Info("Reading value from STDIN") input, err := ioutil.ReadAll(os.Stdin) @@ -139,6 +139,5 @@ var StepUpdateCommand = cli.Command{ if err != nil { l.Fatal("Failed to change step: %s", err) } - return nil }, } diff --git a/cliconfig/loader.go b/cliconfig/loader.go index 2d5288a7b8..cab5ee1693 100644 --- a/cliconfig/loader.go +++ b/cliconfig/loader.go @@ -11,7 +11,7 @@ import ( "github.com/buildkite/agent/v3/logger" "github.com/buildkite/agent/v3/utils" "github.com/oleiade/reflections" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) type Loader struct { @@ -203,8 +203,8 @@ func (l Loader) setFieldValueFromCLI(fieldName string, cliName string) error { // Only set the value if the args are long enough for // the position to exist. - if l.CLI.Args().Len() > argIndex { - value = l.CLI.Args().Get(argIndex) + if len(l.CLI.Args()) > argIndex { + value = l.CLI.Args()[argIndex] } // Otherwise see if we can pull it from an environment variable diff --git a/go.mod b/go.mod index 195b91c73e..ff1dfbb333 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/qri-io/jsonschema v0.0.0-20180607150648-d0d3b10ec792 github.com/sergi/go-diff v1.0.0 // indirect github.com/stretchr/testify v1.5.1 - github.com/urfave/cli/v2 v2.2.0 + github.com/urfave/cli v0.0.0-20180226030253-8e01ec4cd3e2 golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect diff --git a/go.sum b/go.sum index 1ee6961492..0477d41d72 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ cloud.google.com/go v0.0.0-20170217213217-65216237311a h1:jCsBzsjojdK5UhWQfZurxl0ZyWZbvvX9QS5/4rFKGDs= cloud.google.com/go v0.0.0-20170217213217-65216237311a/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895 h1:dmc/C8bpE5VkQn65PNbbyACDC8xw8Hpp/NEurdPmQDQ= github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/aws/aws-sdk-go v1.32.10 h1:cEJTxGcBGlsM2tN36MZQKhlK93O9HrnaRs+lq2f0zN8= @@ -13,8 +12,6 @@ github.com/buildkite/shellwords v0.0.0-20180315084142-c3f497d1e000 h1:hiVSLk7s3y github.com/buildkite/shellwords v0.0.0-20180315084142-c3f497d1e000/go.mod h1:gv0DYOzHEsKgo31lTCDGauIg4DTTGn41Bzp+t3wSOlk= github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 h1:q+sMKdA6L8LyGVudTkpGoC73h6ak2iWSPFiFo/pFOU8= github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3/go.mod h1:5hCug3EZaHXU3FdCA3gJm0YTNi+V+ooA2qNTiVpky4A= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -59,25 +56,19 @@ github.com/qri-io/jsonpointer v0.0.0-20180309164927-168dd9e45cf2 h1:C8RRfIlExwwr github.com/qri-io/jsonpointer v0.0.0-20180309164927-168dd9e45cf2/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64= github.com/qri-io/jsonschema v0.0.0-20180607150648-d0d3b10ec792 h1:vwTGeGWCew89DI4ZwKCaobGAN7ExvZiBzgn4LZHMVOc= github.com/qri-io/jsonschema v0.0.0-20180607150648-d0d3b10ec792/go.mod h1:v+TzC990ezhKzsEvlyorBWqCKtXtv7ihKY0LBSg/45c= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sasha-s/go-deadlock v0.0.0-20180226215254-237a9547c8a5 h1:T7hUw7pBSINuHQyWwMdfIWZZH5M3ju4yXIbuV/Upp+4= github.com/sasha-s/go-deadlock v0.0.0-20180226215254-237a9547c8a5/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= -github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/urfave/cli v0.0.0-20180226030253-8e01ec4cd3e2 h1:98aNRvvwi7jK4ObVo/OnEKs9hw1bZ8JQNpwlB21ILD0= +github.com/urfave/cli v0.0.0-20180226030253-8e01ec4cd3e2/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225 h1:kNX+jCowfMYzvlSvJu5pQWEmyWFrBXJ3PBy10xKMXK8= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= diff --git a/main.go b/main.go index 328840e693..af9f4a2ac9 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( "github.com/buildkite/agent/v3/agent" "github.com/buildkite/agent/v3/clicommand" - "github.com/urfave/cli/v2" + "github.com/urfave/cli" ) var AppHelpTemplate = `Usage: @@ -60,52 +60,51 @@ func main() { app := cli.NewApp() app.Name = "buildkite-agent" app.Version = agent.Version() - app.Commands = []*cli.Command{ - &clicommand.AgentStartCommand, - &clicommand.AnnotateCommand, + app.Commands = []cli.Command{ + clicommand.AgentStartCommand, + clicommand.AnnotateCommand, { Name: "artifact", Usage: "Upload/download artifacts from Buildkite jobs", - Subcommands: []*cli.Command{ - &clicommand.ArtifactUploadCommand, - &clicommand.ArtifactDownloadCommand, - &clicommand.ArtifactSearchCommand, - &clicommand.ArtifactShasumCommand, + Subcommands: []cli.Command{ + clicommand.ArtifactUploadCommand, + clicommand.ArtifactDownloadCommand, + clicommand.ArtifactSearchCommand, + clicommand.ArtifactShasumCommand, }, }, { Name: "meta-data", Usage: "Get/set data from Buildkite jobs", - Subcommands: []*cli.Command{ - &clicommand.MetaDataSetCommand, - &clicommand.MetaDataGetCommand, - &clicommand.MetaDataExistsCommand, - &clicommand.MetaDataKeysCommand, + Subcommands: []cli.Command{ + clicommand.MetaDataSetCommand, + clicommand.MetaDataGetCommand, + clicommand.MetaDataExistsCommand, + clicommand.MetaDataKeysCommand, }, }, { Name: "pipeline", Usage: "Make changes to the pipeline of the currently running build", - Subcommands: []*cli.Command{ - &clicommand.PipelineUploadCommand, + Subcommands: []cli.Command{ + clicommand.PipelineUploadCommand, }, }, { Name: "step", Usage: "Get or update an attribute of a build step", - Subcommands: []*cli.Command{ - &clicommand.StepGetCommand, - &clicommand.StepUpdateCommand, + Subcommands: []cli.Command{ + clicommand.StepGetCommand, + clicommand.StepUpdateCommand, }, }, - &clicommand.BootstrapCommand, + clicommand.BootstrapCommand, } // When no sub command is used - app.Action = func(c *cli.Context) error { + app.Action = func(c *cli.Context) { cli.ShowAppHelp(c) os.Exit(1) - return nil } // When a sub command can't be found