INNER CODE UNIT · Go
promptYesNo
SurgeDM/Surge · cmd/bugreport.go:120
func promptYesNo(reader *bufio.Reader, out io.Writer, prompt string, defaultYes bool) (bool, error) {
for {
_, _ = fmt.Fprint(out, prompt)
choice, eof, err := readPromptLine(reader)
if err != nil {
return false, fmt.Errorf("failed to read selection: %w", err)
}
switch strings.ToLower(choice) {
case "":
return defaultYes, nil
case "y", "yes":
return true, nil
case "n", "no":
return false, nil
default:
_, _ = fmt.Fprintln(out, "Invalid selection. Enter y or n.")