This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
prompt.go
90 lines (82 loc) · 1.67 KB
/
prompt.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package prompt
import (
"github.com/AlecAivazis/survey/v2"
)
func AskQuestionWithInput(response interface{}, name, question, defaultVal string, isRequired bool) error {
prompt := []*survey.Question{
{
Name: name,
Prompt: &survey.Input{
Message: question,
Default: defaultVal,
},
},
}
var err error
if isRequired {
err = Ask(prompt, response, survey.WithValidator(survey.Required))
} else {
err = Ask(prompt, response)
}
if err != nil {
return err
}
return nil
}
func MultiSelect(response interface{}, name, question string, options []string, opts ...survey.AskOpt) error {
prompt := []*survey.Question{
{
Name: name,
Prompt: &survey.MultiSelect{
Message: question,
Options: options,
},
},
}
err := Ask(prompt, response, opts...)
if err != nil {
return err
}
return nil
}
func AskMultiline(response interface{}, name, question string, defaultVal string) error {
prompt := []*survey.Question{
{
Name: name,
Prompt: &survey.Multiline{
Message: question,
Default: defaultVal,
},
},
}
err := Ask(prompt, response)
if err != nil {
return err
}
return nil
}
func Select(response interface{}, name string, question string, options []string, opts ...survey.AskOpt) error {
prompt := []*survey.Question{
{
Name: name,
Prompt: &survey.Select{
Message: question,
Options: options,
},
},
}
err := Ask(prompt, response, opts...)
if err != nil {
return err
}
return nil
}
var AskOne = survey.AskOne
var Ask = survey.Ask
var Confirm = func(result *bool, prompt string, defaultVal bool) error {
p := &survey.Confirm{
Message: prompt,
Default: defaultVal,
}
return survey.AskOne(p, result)
}