MCPcopy Create free account
hub / github.com/foxcpp/maddy / ReadPassword

Function ReadPassword

internal/cli/clitools/clitools.go:89–118  ·  view source on GitHub ↗
(prompt string)

Source from the content-addressed store, hash-verified

87}
88
89func ReadPassword(prompt string) (string, error) {
90 termios, err := TurnOnRawIO(os.Stdin)
91 hiddenPass := true
92 if err != nil {
93 hiddenPass = false
94 fmt.Fprintln(os.Stderr, "Failed to disable terminal output:", err)
95 }
96
97 // There is no meaningful way to handle error here.
98 //nolint:errcheck
99 defer TcSetAttr(os.Stdin.Fd(), &termios)
100
101 fmt.Fprintf(os.Stderr, "%s: ", prompt)
102
103 if hiddenPass {
104 buf := make([]byte, 512)
105 buf, err = readPass(os.Stdin, buf)
106 if err != nil {
107 return "", err
108 }
109 fmt.Println()
110
111 return string(buf), nil
112 }
113 if !stdinScanner.Scan() {
114 return "", stdinScanner.Err()
115 }
116
117 return stdinScanner.Text(), nil
118}

Callers

nothing calls this directly

Calls 5

readPassFunction · 0.85
PrintlnMethod · 0.80
ErrMethod · 0.80
TurnOnRawIOFunction · 0.70
TcSetAttrFunction · 0.70

Tested by

no test coverage detected