/
prompt.go
129 lines (109 loc) · 2.68 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package prompt
import (
"errors"
"os"
"strconv"
"github.com/manifoldco/promptui"
"github.com/urfave/cli/v2"
)
var ErrNonInteractive = errors.New("prompt in non-interactive environment")
type Prompt struct {
inner promptui.Prompt
}
// Run returns the value of the prompt. If a CI environment is detected ErrNonInteractive is returned.
func (p Prompt) Run() (string, error) {
if ci, _ := strconv.ParseBool(os.Getenv("CI")); ci {
return "", ErrNonInteractive
}
return p.inner.Run()
}
// RunFlag returns the value of the flag if set, otherwise the prompt is run normally.
func (p Prompt) RunFlag(c *cli.Context, flag string) (string, error) {
if c.IsSet(flag) {
return c.String(flag), nil
}
return p.Run()
}
func NewAccountPassphrase() Prompt {
return Prompt{promptui.Prompt{
Label: "New account passphrase",
Mask: '*',
HideEntered: true,
Validate: ValidateMinLength(5),
}}
}
func AccountPrivateKey() Prompt {
return Prompt{promptui.Prompt{
Label: "Hex-encoded ECDSA private key",
Mask: '*',
HideEntered: true,
Validate: ValidateMinLength(32),
}}
}
func AccountPassphrase() Prompt {
return Prompt{promptui.Prompt{
Label: "Account passphrase",
Mask: '*',
HideEntered: true,
Validate: ValidateMinLength(5),
}}
}
func OrganizationName(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Organization full name",
Default: value,
Validate: ValidateMinLength(1),
}}
}
func OrganizationDescription(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Organization description",
Default: value,
Validate: ValidateMinLength(1),
}}
}
func OrganizationHomepage(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Organization homepage",
Default: value,
}}
}
func RepositoryName(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Repository full name",
Default: value,
Validate: ValidateMinLength(1),
}}
}
func RepositoryDescription(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Repository description",
Default: value,
Validate: ValidateMinLength(1),
}}
}
func RepositoryHomepage(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Homepage",
Default: value,
}}
}
func RepositoryURL(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Source code repository url",
Default: value,
}}
}
func ReleaseTag(value string) Prompt {
return Prompt{promptui.Prompt{
Label: "Latest release tag",
Default: value,
}}
}
func ReleaseMultiArch() Prompt {
return Prompt{promptui.Prompt{
Label: "Are you building for multiple architecures? (y,N)",
IsConfirm: true,
Validate: ValidateYesNo(),
}}
}