Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper CLI to envtool - envtool setup subcommand #2570

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add proper CLI to envtool
  • Loading branch information
kropidlowsky committed May 4, 2023
commit 9fd2395484c78301214b9dddd2428f9a6ab204d3
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions cmd/envtool/envtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}