2020-02-24 19:14:46 +03:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2021-09-07 16:33:58 +03:00
|
|
|
"github.com/AlecAivazis/survey/v2"
|
2020-02-24 19:14:46 +03:00
|
|
|
)
|
|
|
|
|
2021-09-07 16:33:58 +03:00
|
|
|
func GetYesNoPrompt(message string) (promptResp bool, err error) {
|
|
|
|
prompt := &survey.Confirm{
|
|
|
|
Message: message,
|
|
|
|
Default: true,
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
2021-09-07 16:33:58 +03:00
|
|
|
err = survey.AskOne(prompt, &promptResp)
|
|
|
|
return promptResp, err
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
2021-09-07 16:33:58 +03:00
|
|
|
err = survey.AskOne(prompt, &selection)
|
|
|
|
return selection, err
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
|
|
|
|
2021-01-18 20:11:05 +03:00
|
|
|
func GetInputPrompt(message string) (input string, err error) {
|
2021-09-07 16:33:58 +03:00
|
|
|
prompt := &survey.Input{
|
|
|
|
Message: message,
|
2021-01-18 20:11:05 +03:00
|
|
|
}
|
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
|
2021-01-18 20:11:05 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
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,
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
2021-09-07 16:33:58 +03:00
|
|
|
err = survey.AskOne(prompt, &input, survey.WithValidator(validateDirPath))
|
|
|
|
return input, err
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|