Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
guess stage
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Dec 19, 2023
1 parent 342bbe6 commit c7c9e92
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit c7c9e92

Please sign in to comment.