package input import ( "fmt" "strings" ) // YesOrNo ask user for a yes or no reply and try until we get a possible answer. func YesOrNo() bool { value := Ask(true, func(in string) (string, error) { lUserInput := strings.ToLower(in) for _, positiveAnswer := range []string{"yes", "y", "1", "true"} { if lUserInput == positiveAnswer { return "y", nil } } for _, negativeAnswer := range []string{"no", "n", "0", "false"} { if lUserInput == negativeAnswer { return "n", nil } } return "", fmt.Errorf("expecting a yes or no answer, try again") }) return value == "y" }