diff --git a/cmd/gen.go b/cmd/gen.go index 16c95be..835ac63 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -59,6 +59,7 @@ func (pr *Project) Init(ctx context.Context) { logger.Error("change to project root directory: " + err.Error()) } + // go mod init command mod := platform.Repo cmd := exec.CommandContext(ctx, "go", "mod", "init", mod) @@ -73,6 +74,11 @@ func (pr *Project) Init(ctx context.Context) { logger.Info("go mod init") } + // go mod tidy command + if err := os.Setenv("GO111MODULE", "on"); err != nil { + logger.Error("set GO111MODULE env: " + err.Error()) + } + if _, err := os.Stat("go.mod"); err == nil { cmd := exec.CommandContext(ctx, "go", "mod", "tidy") diff --git a/cmd/root.go b/cmd/root.go index 45d9c1b..4485826 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,7 +20,7 @@ const ( confDir = ".aplcli" idpDir = ".aplcli/platforms" valuesDir = ".aplcli/platforms/values" - version = "1.0.0" + version = "0.1.4" ) type ProjectPaths struct { diff --git a/cmd/setup.go b/cmd/setup.go index f96ea7f..b1fbb0c 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -3,7 +3,6 @@ package cmd import ( "bufio" "context" - "encoding/json" "errors" "fmt" "os" @@ -13,10 +12,6 @@ import ( "time" ) -type PulumiUser struct { - User string `json:"user"` -} - func missingToken(tokenVar string) { var ( envTxt string @@ -66,7 +61,7 @@ func PreChk() { } func GetPulumiUser() string { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() helpTxt := func() { @@ -86,7 +81,15 @@ func GetPulumiUser() string { logger.Error("skip update check: " + err.Error()) } - cmd := exec.CommandContext(ctx, "pulumi", "whoami", "--non-interactive", "--json") + cmdArgs := []string{"whoami", "--non-interactive"} + + // initial cmd run to remove "Logging in using access token from PULUMI_ACCESS_TOKEN" from output + if _, err := exec.CommandContext(ctx, "pulumi", cmdArgs...).Output(); err != nil { + logger.Error("pulumi login: initial login " + err.Error()) + } + + // run again with context and grab only pulumi user from output + cmd := exec.CommandContext(ctx, "pulumi", cmdArgs...) stdout, err := cmd.CombinedOutput() if err != nil { @@ -99,13 +102,7 @@ func GetPulumiUser() string { } } - var pulumiUser PulumiUser - - if err := json.Unmarshal(stdout, &pulumiUser); err != nil { - logger.Error("json unmarshal data from `pulumi whoami` command: " + err.Error()) - } - - return pulumiUser.User + return string(stdout) } func SetupPrompt(promptStr string) string {