-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathregistry.go
More file actions
111 lines (96 loc) · 4.04 KB
/
registry.go
File metadata and controls
111 lines (96 loc) · 4.04 KB
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
package parser
import (
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/internal/completion"
"github.com/drycc/workflow-cli/internal/template"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// no default web
var registryFlags struct {
ptype string
}
func NewRegistryCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "registry",
Short: i18n.T("Manage private registry information for your application"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.RegistryList(app, registryFlags.ptype, version)
},
}
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name for the application"))
cmd.Flags().StringVarP(®istryFlags.ptype, "ptype", "p", "", i18n.T("The ptype for registry"))
cmd.Flags().IntVarP(&version, "version", "v", 0, i18n.T("The version for which the registry needs to be listed"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
cmd.AddCommand(registryListCommand(cmdr))
cmd.AddCommand(registrySetCommand(cmdr))
cmd.AddCommand(registryUnsetCommand(cmdr))
return cmd
}
func registryListCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: i18n.T("List registry info for an app"),
Long: i18n.T("Lists registry information for an application"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.RegistryList(app, registryFlags.ptype, version)
},
}
cmd.Flags().StringVarP(®istryFlags.ptype, "ptype", "p", "", i18n.T("The ptype for registry"))
cmd.Flags().IntVarP(&version, "version", "v", 0, i18n.T("The version for which the registry needs to be listed"))
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
releaseCompletion := completion.ReleaseCompletion{ConfigFile: &cmdr.ConfigFile, AppID: &app}
cmd.RegisterFlagCompletionFunc("version", releaseCompletion.CompletionFunc)
return cmd
}
func registrySetCommand(cmdr *commands.DryccCmd) *cobra.Command {
// default web
var flags struct {
ptype string
}
cmd := &cobra.Command{
Use: "set <username> <password>",
Args: cobra.ExactArgs(2),
Example: template.CustomExample(
"drycc registry set username password",
map[string]string{
"<username>": i18n.T("The username of the registry"),
"<password>": i18n.T("The password of the registry"),
},
),
Short: i18n.T("Set registry info for an app"),
Long: i18n.T(`Sets registry information for an application. These credentials are the same as those used for
'podmain login' to the private registry.`),
RunE: func(cmd *cobra.Command, args []string) error {
username := args[0]
password := args[1]
return cmdr.RegistrySet(app, flags.ptype, username, password)
},
}
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The ptype for registry"))
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
return cmd
}
func registryUnsetCommand(cmdr *commands.DryccCmd) *cobra.Command {
// default web
var flags struct {
ptype string
}
cmd := &cobra.Command{
Use: "unset",
Short: i18n.T("Unset registry info for an app"),
Long: i18n.T("Unsets registry information for an application"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.RegistryUnset(app, flags.ptype)
},
}
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The ptype for registry"))
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
return cmd
}