-
Notifications
You must be signed in to change notification settings - Fork 1
/
input.go
47 lines (42 loc) · 945 Bytes
/
input.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
package ui
import (
"strings"
"github.com/manifoldco/promptui"
)
func GetInput(title string, validator func(string) error) string {
prompt := promptui.Prompt{
Label: title,
Validate: validator,
}
result, err := prompt.Run()
if err != nil {
Fatal("User input failed", err)
}
return result
}
func GetMaskedInput(title string, validator func(string) error) string {
prompt := promptui.Prompt{
Label: title,
Validate: validator,
Mask: '*',
}
result, err := prompt.Run()
if err != nil {
Fatal("User input failed", err)
}
return result
}
func DestructiveConfirmation() {
prompt := promptui.Prompt{
Label: "What you are about to do could be destructive, continue?",
IsConfirm: true,
}
result, err := prompt.Run()
if err != nil {
Fatal("destructive confirmation failed", err)
}
if strings.ToLower(result) != "y" {
Error("Aborted!")
FatalQuiet("destructive confirmation rejected", err)
}
}