mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
a398d3b190
GITHUB_PR_NUMBER: 6111 GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/6111 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 1f6517acfacb58c566bb5e48f74ea0dfa5c6f063
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package util
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/manifoldco/promptui"
|
|
)
|
|
|
|
const (
|
|
INVALID_YES_NO_RESP_ERROR = "invalid response, please enter Y or N"
|
|
)
|
|
|
|
func GetYesNoPrompt(message string) (promptResp string, err error) {
|
|
prompt := promptui.Prompt{
|
|
Label: message + " (y/n)",
|
|
Validate: func(_resp string) (err error) {
|
|
if len(_resp) == 0 {
|
|
err = errors.New(INVALID_YES_NO_RESP_ERROR)
|
|
return
|
|
}
|
|
resp := strings.ToLower(_resp)
|
|
if resp != "n" && resp != "y" && resp != "no" && resp != "yes" {
|
|
err = errors.New(INVALID_YES_NO_RESP_ERROR)
|
|
}
|
|
return err
|
|
},
|
|
Default: "y",
|
|
}
|
|
promptResp, err = prompt.Run()
|
|
if err != nil {
|
|
return
|
|
}
|
|
promptResp = string(strings.ToLower(promptResp)[0])
|
|
return
|
|
}
|
|
|
|
func GetSelectPrompt(message string, options []string) (selection string, err error) {
|
|
prompt := promptui.Select{
|
|
Label: message,
|
|
Items: options,
|
|
}
|
|
_, selection, err = prompt.Run()
|
|
return
|
|
}
|
|
|
|
func GetInputPrompt(message string) (input string, err error) {
|
|
prompt := promptui.Prompt{
|
|
Label: message,
|
|
}
|
|
input, err = prompt.Run()
|
|
return
|
|
}
|
|
|
|
func GetFSPathPrompt(message string, def string) (input string, err error) {
|
|
prompt := promptui.Prompt{
|
|
Label: message,
|
|
Validate: FSCheckIfDirPathExists,
|
|
Default: def,
|
|
}
|
|
return prompt.Run()
|
|
}
|