Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Add stub login command to continue exploring
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Apr 14, 2020
1 parent ba4e5ca commit dc03b99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"

"github.com/AlecAivazis/survey/v2"
"github.com/mgutz/ansi"
"github.com/spf13/cobra"
)

Expand All @@ -40,18 +41,21 @@ var loginCmd = &cobra.Command{
Short: "Login to the Opsani API",
Long: `Login to the Opsani API and persist access credentials.`,
Run: func(cmd *cobra.Command, args []string) {
if loginConfig.Username == "" {
fmt.Println("Logging into api.opsani.com")

whiteBold := ansi.ColorCode("white+b")
if loginConfig.Username == "" {
survey.AskOne(&survey.Input{
Message: "Username:",
}, &loginConfig.Username, survey.WithValidator(survey.Required))
} else {
fmt.Printf("%si %sUsername: %s%s%s%s\n", ansi.Blue, whiteBold, ansi.Reset, ansi.LightCyan, loginConfig.Username, ansi.Reset)
}

if loginConfig.Password == "" {
fmt.Println("Logging into api.opsani.com")
survey.AskOne(&survey.Input{
Message: "Username:",
}, &loginConfig.Username)
survey.AskOne(&survey.Password{
Message: "Password:",
}, &loginConfig.Password)
}, &loginConfig.Password, survey.WithValidator(survey.Required))
}
},
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/kyoh86/richgo v0.3.3 // indirect
github.com/kyoh86/xdg v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
Expand Down

0 comments on commit dc03b99

Please sign in to comment.