forked from erickson74/authtool-origin
/
prompt.go
49 lines (42 loc) · 952 Bytes
/
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
package common
import (
"errors"
"github.com/manifoldco/promptui"
"strings"
)
func ValidateEmptyInput(input string) error {
if len(strings.TrimSpace(input)) < 1 {
return errors.New("this input must not be empty")
}
return nil
}
func PromptString(name string, currentValue string, isConfirm bool) (string, error) {
prompt := promptui.Prompt{
Label: name,
Validate: ValidateEmptyInput,
Default: currentValue,
IsConfirm: isConfirm,
}
return prompt.Run()
}
func PromptSelect(name string, items []string) (int, string, error){
prompt := promptui.Select{
Label: name,
Items: items,
}
return prompt.Run()
}
//func PromptInteger(name string) (int64, error) {
// prompt := promptui.Prompt{
// Label: name,
// Validate: ValidateIntegerNumberInput,
// }
//
// promptResult, err := prompt.Run()
// if err != nil {
// return 0, err
// }
//
// parseInt, _ := strconv.ParseInt(promptResult, 0, 64)
// return parseInt, nil
//}