Skip to content

Commit

Permalink
Added last used hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
Matija Pevec committed Jan 10, 2020
1 parent e9b37a4 commit e95998b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cmd/auth.go
Expand Up @@ -121,11 +121,29 @@ func interactiveLoginInputFunc(_ *cobra.Command, _ []string) {
}{os.Stdin, os.Stdout}
t := terminal.NewTerminal(screen, "")

hostname = AskForText(t, "Hostname: ", false)
hostname = AskForHostname(t)
username = AskForText(t, "Username: ", false)
password = AskForText(t, "Password: ", true)
}

func AskForHostname(t *terminal.Terminal) string {
previousHost := viper.GetString(config.Hostname)
var prefix string
if previousHost != "" {
prefix = fmt.Sprintf("Hostname (%s): ", previousHost)
} else {
prefix = fmt.Sprintf("Hostname: ")
}

userInput := AskForText(t, prefix, false)

if userInput == "" && previousHost != "" {
return previousHost
}

return userInput
}

func AskForText(t *terminal.Terminal, prefix string, hidden bool) string {
prompt := string(t.Escape.Cyan) + prefix + string(t.Escape.Reset)

Expand All @@ -148,7 +166,6 @@ func AskForText(t *terminal.Terminal, prefix string, hidden bool) string {

func logoutFunc(_ *cobra.Command, _ []string) {
viper.Set(config.ApiKey, "")
viper.Set(config.Hostname, "")
err := viper.WriteConfig()

if err != nil {
Expand Down

0 comments on commit e95998b

Please sign in to comment.