(prompt string)
| 87 | } |
| 88 | |
| 89 | func 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 | } |
nothing calls this directly
no test coverage detected