-
Notifications
You must be signed in to change notification settings - Fork 23
/
registry_add.go
59 lines (50 loc) · 1.12 KB
/
registry_add.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
package cmd
import (
"fmt"
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func (r *runners) InitRegistryAdd(parent *cobra.Command) *cobra.Command {
cmd := &cobra.Command{
Use: "add",
Short: "add",
Long: `add`,
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.PersistentFlags().BoolVar(&r.args.addRegistrySkipValidation, "skip-validation", false, "Skip validation of the registry (not recommended)")
return cmd
}
func contains(vals []string, val string) bool {
for _, v := range vals {
if v == val {
return true
}
}
return false
}
func (r *runners) readPasswordFromStdIn(label string) (string, error) {
prompt := promptui.Prompt{
Label: fmt.Sprintf("%s:", label),
Mask: '*',
Templates: templates,
Default: "",
Validate: func(input string) error {
if len(input) == 0 {
return errors.New("password cannot be empty")
}
return nil
},
}
for {
result, err := prompt.Run()
if err != nil {
if err == promptui.ErrInterrupt {
return "", errors.New("interrupted")
}
continue
}
return result, nil
}
}