From c7c9e925a72063399f2d8659e354de71594f957c Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Mon, 18 Dec 2023 21:16:26 -0500 Subject: [PATCH] guess stage --- cmd/sst/main.go | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/cmd/sst/main.go b/cmd/sst/main.go index 3d77d8a39..4b5c194cd 100644 --- a/cmd/sst/main.go +++ b/cmd/sst/main.go @@ -6,6 +6,8 @@ import ( "log/slog" "os" "os/signal" + "os/user" + "strings" "github.com/sst/ion/cmd/sst/ui" "github.com/sst/ion/pkg/global" @@ -225,22 +227,39 @@ func initProject(cli *cli.Context) (*project.Project, error) { if app.Stage == "" { p.LoadPersonalStage() if app.Stage == "" { - for { - var stage string - fmt.Print("Enter a stage name for your personal stage: ") - _, err := fmt.Scanln(&stage) - if err != nil { - continue - } - if stage == "" { - continue + var stage string + stage = guessStage() + if stage == "" { + for { + fmt.Print("Enter a stage name for your personal stage: ") + _, err := fmt.Scanln(&stage) + if err != nil { + continue + } + if stage == "" { + continue + } + break } - p.SetPersonalStage(stage) - break } + p.SetPersonalStage(stage) } } slog.Info("loaded config", "app", app.Name, "stage", app.Stage) return p, nil } + +func guessStage() string { + u, err := user.Current() + if err != nil { + return "" + } + stage := strings.ToLower(u.Username) + + if stage == "root" || stage == "admin" || stage == "prod" || stage == "dev" || stage == "production" { + return "" + } + + return stage +}