diff --git a/ShowQuestion.go b/ShowQuestion.go new file mode 100644 index 0000000..537e37a --- /dev/null +++ b/ShowQuestion.go @@ -0,0 +1,35 @@ +import ( + "errors" + "fmt" + "strings" + + "github.com/manifoldco/promptui" +) + +func ShowQuestion(message string) bool { + allowedValues := [...]string{"y", "yes", "no", "n"} + + validate := func(input string) error { + for _, value := range allowedValues { + if strings.ToLower(input) == value { + return nil + } + } + return errors.New(fmt.Sprintf("Number should be one of the values %v", allowedValues)) + } + + prompt := promptui.Prompt{ + Label: message, + Validate: validate, + Default: "y", + } + + result, err := prompt.Run() + if err != nil { + return ShowQuestion(message) + } + + result = strings.ToLower(result) + + return result == "y" || result == "yes" +}