Skip to content
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
6 changes: 6 additions & 0 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 11 additions & 14 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -13,10 +12,6 @@ import (
"time"
)

type PulumiUser struct {
User string `json:"user"`
}

func missingToken(tokenVar string) {
var (
envTxt string
Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Loading