-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdomains.go
More file actions
84 lines (71 loc) · 2.67 KB
/
domains.go
File metadata and controls
84 lines (71 loc) · 2.67 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
package parser
import (
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/internal/completion"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// NewDomainsCommand creates the domains command
func NewDomainsCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "domains",
Short: i18n.T("Manage and assign domain names to your applications"),
RunE: func(_ *cobra.Command, _ []string) error {
results, _ := commands.ResponseLimit(limit)
return cmdr.DomainsList(app, results)
},
}
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name for the application"))
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
cmd.AddCommand(domainsListCommand(cmdr))
cmd.AddCommand(domainsAddCommand(cmdr))
cmd.AddCommand(domainsRemoveCommand(cmdr))
return cmd
}
func domainsListCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: i18n.T("List domains bound to an application"),
RunE: func(_ *cobra.Command, _ []string) error {
results, _ := commands.ResponseLimit(limit)
return cmdr.DomainsList(app, results)
},
}
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
return cmd
}
func domainsAddCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
ptype string
}
cmd := &cobra.Command{
Use: "add <domain>",
Args: cobra.ExactArgs(1),
Short: i18n.T("Bind a domain to an application"),
RunE: func(_ *cobra.Command, args []string) error {
domain := args[0]
return cmdr.DomainsAdd(app, domain, flags.ptype)
},
}
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The ptype for domain"))
cmd.MarkFlagRequired("ptype")
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
return cmd
}
func domainsRemoveCommand(cmdr *commands.DryccCmd) *cobra.Command {
domainCompletion := completion.DomainCompletion{AppID: &app, ArgsLen: 0, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "remove <domain>",
Args: cobra.ExactArgs(1),
Short: i18n.T("Unbinds a domain for an application"),
ValidArgsFunction: domainCompletion.CompletionFunc,
RunE: func(_ *cobra.Command, args []string) error {
domain := args[0]
return cmdr.DomainsRemove(app, domain)
},
}
return cmd
}