(out io.Writer, reader *bufio.Reader, label, defaultValue string)
| 1203 | } |
| 1204 | |
| 1205 | func promptWithDefault(out io.Writer, reader *bufio.Reader, label, defaultValue string) (string, error) { |
| 1206 | label = strings.TrimSpace(label) |
| 1207 | prompt := label |
| 1208 | if defaultValue != "" { |
| 1209 | prompt += fmt.Sprintf(" [%s]", defaultValue) |
| 1210 | } |
| 1211 | prompt += ": " |
| 1212 | fmt.Fprint(out, prompt) |
| 1213 | |
| 1214 | line, err := reader.ReadString('\n') |
| 1215 | if err != nil && !errors.Is(err, io.EOF) { |
| 1216 | return "", fmt.Errorf("read input: %w", err) |
| 1217 | } |
| 1218 | line = strings.TrimRight(line, "\r\n") |
| 1219 | if strings.TrimSpace(line) == "" { |
| 1220 | return defaultValue, nil |
| 1221 | } |
| 1222 | return line, nil |
| 1223 | } |
| 1224 | |
| 1225 | func promptYesNo(out io.Writer, in io.Reader, label string, defaultYes bool) (bool, error) { |
| 1226 | reader := bufio.NewReader(in) |
no outgoing calls
no test coverage detected