-
Notifications
You must be signed in to change notification settings - Fork 190
/
prompt.go
58 lines (43 loc) · 1.05 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
package util
import (
"strings"
"github.com/AlecAivazis/survey/v2"
)
// PromptPlaintext prompts a user to input plain text
func PromptPlaintext(message string, defaultVal string) (string, error) {
var (
prompt = survey.Input{
Message: message,
Default: defaultVal,
}
value string
)
if err := survey.AskOne(&prompt, &value, survey.WithValidator(survey.Required)); err != nil {
return "", err
}
return strings.TrimSpace(value), nil
}
// PromptPassword prompts a user to input a hidden field
func PromptPassword(message string) (string, error) {
var (
prompt = &survey.Password{Message: message}
password string
)
if err := survey.AskOne(prompt, &password, survey.WithValidator(survey.Required)); err != nil {
return "", err
}
return strings.TrimSpace(password), nil
}
func PromptConfirm(message string, defaultVal bool) (bool, error) {
var (
prompt = &survey.Confirm{
Message: message,
Default: defaultVal,
}
value bool
)
if err := survey.AskOne(prompt, &value); err != nil {
return false, err
}
return value, nil
}