MCPcopy Create free account
hub / github.com/git-bug/git-bug / PromptPassword

Function PromptPassword

commands/input/prompt.go:93–132  ·  view source on GitHub ↗

PromptPassword is a specialized text input that doesn't display the characters entered.

(prompt, name string, validators ...PromptValidator)

Source from the content-addressed store, hash-verified

91
92// PromptPassword is a specialized text input that doesn't display the characters entered.
93func PromptPassword(prompt, name string, validators ...PromptValidator) (string, error) {
94 termState, err := terminal.GetState(int(syscall.Stdin))
95 if err != nil {
96 return "", err
97 }
98
99 cancel := interrupt.RegisterCleaner(func() error {
100 return terminal.Restore(int(syscall.Stdin), termState)
101 })
102 defer cancel()
103
104loop:
105 for {
106 _, _ = fmt.Fprintf(os.Stderr, "%s: ", prompt)
107
108 bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
109 // new line for coherent formatting, ReadPassword clip the normal new line
110 // entered by the user
111 fmt.Println()
112
113 if err != nil {
114 return "", err
115 }
116
117 pass := string(bytePassword)
118
119 for _, validator := range validators {
120 complaint, err := validator(name, pass)
121 if err != nil {
122 return "", err
123 }
124 if complaint != "" {
125 _, _ = fmt.Fprintln(os.Stderr, complaint)
126 continue loop
127 }
128 }
129
130 return pass, nil
131 }
132}
133
134// PromptChoice is a prompt giving possible choices
135// Return the index starting at zero of the choice selected.

Callers 2

buildClientFunction · 0.92
promptCredOptionsFunction · 0.92

Calls 2

RegisterCleanerFunction · 0.92
PrintlnMethod · 0.65

Tested by

no test coverage detected