From 9fd2395484c78301214b9dddd2428f9a6ab204d3 Mon Sep 17 00:00:00 2001 From: kropidlowsky Date: Thu, 4 May 2023 21:43:47 +0200 Subject: [PATCH] Add proper CLI to envtool --- Taskfile.yml | 2 +- cmd/envtool/envtool.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 116680b89841..58ecc48138bc 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -94,7 +94,7 @@ tasks: env-setup: deps: [gen-version] cmds: - - go run {{.RACEFLAG}} ./cmd/envtool + - go run {{.RACEFLAG}} ./cmd/envtool setup env-logs: cmds: diff --git a/cmd/envtool/envtool.go b/cmd/envtool/envtool.go index 60683b8f8a2b..6b23bbbd60dc 100644 --- a/cmd/envtool/envtool.go +++ b/cmd/envtool/envtool.go @@ -324,11 +324,12 @@ func printDiagnosticData(setupError error, logger *zap.SugaredLogger) { // cli struct represents all command-line commands, fields and flags. // It's used for parsing the user input. var cli struct { - Debug bool `help:"Enable debug mode."` + Debug bool `help:"Enable debug mode."` + Setup struct{} `cmd:""` } func main() { - kong.Parse(&cli) + kongCtx := kong.Parse(&cli) // always enable debug logging on CI if t, _ := strconv.ParseBool(os.Getenv("CI")); t { @@ -346,8 +347,11 @@ func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - if err := setup(ctx, logger); err != nil { - printDiagnosticData(err, logger) - os.Exit(1) + switch kongCtx.Command() { + case "setup": + if err := setup(ctx, logger); err != nil { + printDiagnosticData(err, logger) + os.Exit(1) + } } }