-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompts.go
51 lines (40 loc) · 898 Bytes
/
prompts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ui
import (
"github.com/AlecAivazis/survey/v2"
)
type PromptOptions struct {
Suggest func(toComplete string) []string
}
func PromptInput(msg string, v interface{}, opts ...*PromptOptions) error {
p := &survey.Input{
Message: msg,
}
if len(opts) > 0 {
if opts[0].Suggest != nil {
p.Suggest = opts[0].Suggest
}
}
return survey.AskOne(p, v)
}
func PromptEmail(v interface{}) error {
return PromptInput("Enter your email:", v)
}
func PromptPassword(v interface{}) error {
p := &survey.Password{
Message: "Enter your password:",
}
return survey.AskOne(p, v)
}
func PromptYesNo(message string, v interface{}) error {
p := &survey.Confirm{
Message: message,
}
return survey.AskOne(p, v)
}
func PromptSelect(message string, options []string, v interface{}) error {
p := &survey.Select{
Message: message,
Options: options,
}
return survey.AskOne(p, v)
}