graphql-engine/cli/util/prompt.go
hasura-bot a398d3b190 cli: support datasources
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
2021-01-18 17:12:09 +00:00

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()
}