-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompts.go
47 lines (41 loc) · 919 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
package configs
import (
"fmt"
"os"
"strings"
"github.com/manifoldco/promptui"
)
func Confirm(message string, defaultValue bool) bool {
dV := "y"
if !defaultValue {
dV = "n"
}
prompt := promptui.Prompt{
Label: message,
IsConfirm: true,
Default: dV,
}
result, err := prompt.Run()
return err == nil && strings.HasPrefix(strings.ToUpper(result), "Y")
}
func Prompt(message string, defaultValue string) (value string, err error) {
prompt := promptui.Prompt{
Label: message,
Default: defaultValue,
}
return prompt.Run()
}
func PromptPath(message string, defaultPath string) (value string, err error) {
validatePath := func(path string) error {
if _, err := os.Stat(path); err != nil {
return fmt.Errorf("path not found [%s]", path)
}
return nil
}
prompt := promptui.Prompt{
Label: message,
Default: defaultPath,
Validate: validatePath,
}
return prompt.Run()
}