Skip to content

Commit

Permalink
fix: masked prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
seriouspoop committed Sep 2, 2024
1 parent f96dad4 commit 45823bd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 9 additions & 7 deletions svc/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package svc

import (
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -51,7 +50,7 @@ func (s *Svc) SetUserPreference() error {
}
utils.Logger(utils.LOG_INFO, "Gathering default settings...")
if cfg.DefaultRemote == "" {
remoteName, err := utils.Prompt("remote (default=origin)")
remoteName, err := utils.Prompt("remote (default=origin)", false)
if err != nil {
return err
}
Expand All @@ -62,7 +61,7 @@ func (s *Svc) SetUserPreference() error {
cfg.DefaultRemote = remoteName
}
if cfg.BranchPrefix == "" {
branchPrefix, err := utils.Prompt("branch prefix (default=empty)")
branchPrefix, err := utils.Prompt("branch prefix (default=empty)", false)
if err != nil {
return err
}
Expand Down Expand Up @@ -94,10 +93,10 @@ func (s *Svc) SetRemoteAuth() error {
return err
}

utils.Logger(utils.LOG_INFO, "Gathering auth details...")
provider := remoteDetails.Provider()
if cfg.ProviderAuth(provider) == nil {
fmt.Println("\nAuth credentials not found.")
fmt.Println("Gathering auth details...")
utils.Logger(utils.LOG_FAILURE, "auth credentials not found")
username, token, err := s.authInput(provider.String())
if err != nil {
return err
Expand All @@ -114,19 +113,22 @@ func (s *Svc) SetRemoteAuth() error {
case model.ProviderGITLAB:
cfg.Auth.GitLab = cred
}
utils.Logger(utils.LOG_SUCCESS, "auth generated")
} else {
utils.Logger(utils.LOG_SUCCESS, "auth found")
}
return cfg.Write(configFile, userDir)
}

func (s *Svc) authInput(provider string) (string, string, error) {
var username, token string
username, err := utils.Prompt("%s username", provider)
username, err := utils.Prompt("%s username", false, provider)
if err != nil {
return "", "", err
}
username = strings.TrimSpace(username)

token, err = utils.Prompt("%s token", provider)
token, err = utils.Prompt("%s token", true, provider)
if err != nil {
return "", "", err
}
Expand Down
4 changes: 2 additions & 2 deletions svc/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *Svc) InitializeRemote() error {
var remoteURL string
utils.Logger(utils.LOG_INFO, "Adding remote...")

remoteURL, err := utils.Prompt("remote url")
remoteURL, err := utils.Prompt("remote url", false)
if err != nil {
return err
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func generateCommitMsg() (string, error) {
commitType = shortner[commitType]
}

msg, err := utils.Prompt("commit message")
msg, err := utils.Prompt("commit message", false)
if err != nil {
return "", err
}
Expand Down
6 changes: 5 additions & 1 deletion utils/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func valid(s string) error {
return nil
}

func Prompt(label string, opts ...interface{}) (res string, err error) {
func Prompt(label string, password bool, opts ...interface{}) (res string, err error) {
template := &promptui.PromptTemplates{
Valid: "{{ . }}: ",
Success: "{{ `\U00002714` | green }} {{ . | faint}}{{ `:` | faint}} ",
Expand All @@ -30,6 +30,10 @@ func Prompt(label string, opts ...interface{}) (res string, err error) {
Validate: valid,
}

if password {
prompt.Mask = '*'
}

res, err = prompt.Run()
return
}

0 comments on commit 45823bd

Please sign in to comment.