Skip to content

Commit 68f2743

Browse files
authored
Merge pull request #58 from buildkite/make-config-file-cli-arg
Add 'config' argument to CLI with .buildkite/cache.yml as a default
2 parents ad3525f + 23d1151 commit 68f2743

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ import (
1717
)
1818

1919
var (
20-
version = "dev"
20+
version = "dev"
21+
defaultConfigPath = ".buildkite/cache.yml"
2122

2223
cli struct {
2324
Version kong.VersionFlag
24-
Debug bool `help:"Enable debug mode." default:"false" env:"BUILDKITE_ZSTASH_DEBUG"`
25-
Endpoint string `flag:"endpoint" help:"The endpoint to use. Defaults to the Buildkite agent API endpoint." default:"https://agent.buildkite.com/v3" env:"BUILDKITE_AGENT_API_ENDPOINT"`
26-
Token string `flag:"token" help:"The buildkite agent access token to use." env:"BUILDKITE_AGENT_ACCESS_TOKEN" required:"true"`
27-
TraceExporter string `flag:"trace-exporter" help:"The trace exporter to use. Defaults to 'noop'." default:"noop" enum:"noop,grpc" env:"BUILDKITE_ZSTASH_TRACE_EXPORTER"`
25+
Debug bool `help:"Enable debug mode." default:"false" env:"BUILDKITE_ZSTASH_DEBUG"`
26+
Endpoint string `flag:"endpoint" help:"The endpoint to use. Defaults to the Buildkite agent API endpoint." default:"https://agent.buildkite.com/v3" env:"BUILDKITE_AGENT_API_ENDPOINT"`
27+
Token string `flag:"token" help:"The buildkite agent access token to use." env:"BUILDKITE_AGENT_ACCESS_TOKEN" required:"true"`
28+
TraceExporter string `flag:"trace-exporter" help:"The trace exporter to use. Defaults to 'noop'." default:"noop" enum:"noop,grpc" env:"BUILDKITE_ZSTASH_TRACE_EXPORTER"`
29+
Config kong.ConfigFlag `flag:"config" help:"The path to the cache configuration file. Defaults to .buildkite/cache.yml" default:"${default_config_path}" env:"BUILDKITE_CACHE_CONFIG" `
2830

2931
commands.CommonFlags
3032

31-
Caches []cache.Cache // embedded configuration for caches
33+
Caches []cache.Cache // embedded config
3234

3335
Save commands.SaveCmd `cmd:"" help:"save files."`
3436
Restore commands.RestoreCmd `cmd:"" help:"restore files."`
@@ -41,12 +43,11 @@ func main() {
4143

4244
start := time.Now()
4345

46+
// Overloads `cli` with configuration file values.
4447
cmd := kong.Parse(&cli,
45-
kong.Vars{
46-
"version": version,
47-
},
48+
kong.Vars{"version": version, "default_config_path": defaultConfigPath},
4849
kong.NamedMapper("yamlfile", kongyaml.YAMLFileMapper),
49-
kong.Configuration(kongyaml.Loader, ".buildkite/cache.yaml", ".buildkite/cache.yml", ".buildkite/cache.json"),
50+
kong.Configuration(kongyaml.Loader),
5051
kong.BindTo(ctx, (*context.Context)(nil)))
5152

5253
// check the token is set
@@ -76,7 +77,7 @@ func main() {
7677
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}).Level(zerolog.ErrorLevel)
7778
}
7879

79-
err = cmd.Run(&commands.Globals{Debug: cli.Debug, Version: version, Client: client, Printer: printer, Caches: cli.Caches, Common: cli.CommonFlags})
80+
err = cmd.Run(&commands.Globals{Debug: cli.Debug, Version: version, Client: client, Printer: printer, Common: cli.CommonFlags, Caches: cli.Caches})
8081
span.RecordError(err)
8182
cmd.FatalIfErrorf(err)
8283

0 commit comments

Comments
 (0)