graphql-engine/cli/util/prompt.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.2 KiB
Go
Raw Normal View History

package util
import (
2021-09-07 16:33:58 +03:00
"github.com/AlecAivazis/survey/v2"
)
2021-09-07 16:33:58 +03:00
func GetYesNoPrompt(message string) (promptResp bool, err error) {
prompt := &survey.Confirm{
Message: message,
Default: true,
}
2021-09-07 16:33:58 +03:00
err = survey.AskOne(prompt, &promptResp)
return promptResp, err
}
func GetSelectPrompt(message string, options []string) (selection string, err error) {
2021-09-07 16:33:58 +03:00
prompt := &survey.Select{
Message: message,
Options: options,
}
2021-09-07 16:33:58 +03:00
err = survey.AskOne(prompt, &selection)
return selection, err
}
func GetInputPrompt(message string) (input string, err error) {
2021-09-07 16:33:58 +03:00
prompt := &survey.Input{
Message: message,
}
2021-09-07 16:33:58 +03:00
err = survey.AskOne(prompt, &input)
return input, err
}
func GetInputPromptWithDefault(message string, def string) (input string, err error) {
prompt := &survey.Input{
Message: message,
Default: def,
}
err = survey.AskOne(prompt, &input)
return input, err
}
func validateDirPath(a interface{}) error {
err := FSCheckIfDirPathExists(a.(string))
return err
}
func GetFSPathPrompt(message string, def string) (input string, err error) {
2021-09-07 16:33:58 +03:00
prompt := &survey.Input{
Message: message,
Default: def,
}
2021-09-07 16:33:58 +03:00
err = survey.AskOne(prompt, &input, survey.WithValidator(validateDirPath))
return input, err
}