diff --git a/cli/config.go b/cli/config.go index 8efa5b204..c5cc7e64b 100644 --- a/cli/config.go +++ b/cli/config.go @@ -76,6 +76,7 @@ func getDefaultConfig() cvpmConfig { func validateConfig() { localConfig := readConfig() + homepath, _ := homedir.Dir() // Validate CVPM Path cvpmPath := filepath.Join(homepath, "cvpm") exist, err := isPathExists(cvpmPath) diff --git a/cli/handler.go b/cli/handler.go index 550877c93..20d627b7e 100644 --- a/cli/handler.go +++ b/cli/handler.go @@ -7,6 +7,8 @@ import ( "github.com/mitchellh/go-homedir" "github.com/olekukonko/tablewriter" "github.com/urfave/cli" + "golang.org/x/crypto/ssh/terminal" + "syscall" "log" "os" "path/filepath" @@ -14,7 +16,7 @@ import ( "strings" ) -func LoginHandler(c *cli.Context) { +func LoginHandler(c *cli.Context) User { reader := bufio.NewReader(os.Stdin) fmt.Printf("Username: ") username, _ := reader.ReadString('\n') @@ -23,7 +25,8 @@ func LoginHandler(c *cli.Context) { bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin)) password := strings.TrimSpace(string(bytePassword)) u := User{username, password, ""} - currentUser = u.login() + currentUser := u.login() + return currentUser } func InstallHandler(c *cli.Context) { diff --git a/cli/main.go b/cli/main.go index 84608c78e..f57643f8b 100644 --- a/cli/main.go +++ b/cli/main.go @@ -1,17 +1,13 @@ package main import ( - "bufio" - "fmt" "github.com/urfave/cli" - "golang.org/x/crypto/ssh/terminal" "log" "os" - "strings" - "syscall" ) func main() { + validateConfig() // sessionToken := getCache("session-token") var currentUser User // if sessionToken != "" { @@ -25,7 +21,7 @@ func main() { { Name: "login", Action: func(c *cli.Context) error { - LoginHandler(c) + currentUser = LoginHandler(c) return nil }, },