-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpts.go
More file actions
164 lines (144 loc) · 4.85 KB
/
pts.go
File metadata and controls
164 lines (144 loc) · 4.85 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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"
)
func NewPtsCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "pts",
Short: i18n.T("Manage process types inside an app"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.PtsList(app, 1000)
},
}
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name for the application"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
cmd.AddCommand(ptsListCommand(cmdr))
cmd.AddCommand(ptsDescribeCommand(cmdr))
cmd.AddCommand(ptsRestartCommand(cmdr))
cmd.AddCommand(ptsScaleCommand(cmdr))
cmd.AddCommand(ptsCleanCommand(cmdr))
return cmd
}
// ptsListCommand
func ptsListCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: i18n.T("List application process types"),
Long: i18n.T("Lists process types servicing an application"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.PtsList(app, 1000)
},
}
return cmd
}
// ptsDescribeCommand
func ptsDescribeCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
ptype string
}
ptsArgsCompletion := completion.PtsArgsCompletion{
PtsCompletion: &completion.PtsCompletion{AppID: &app, ArgsLen: 0, ConfigFile: &cmdr.ConfigFile},
}
cmd := &cobra.Command{
Use: "describe <ptype>",
Args: cobra.ExactArgs(1),
Example: template.CustomExample(
"drycc pts describe web",
map[string]string{
"<ptype>": i18n.T("The process name as defined in your Procfile"),
},
),
Short: i18n.T("Describe a process type"),
Long: i18n.T("Print a detailed description of the selected process type"),
ValidArgsFunction: ptsArgsCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
flags.ptype = args[0]
return cmdr.PtsDescribe(app, flags.ptype)
},
}
return cmd
}
// ptsRestartCommand
func ptsRestartCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
ptypes []string
confirm string
}
ptsArgsCompletion := completion.PtsArgsCompletion{
PtsCompletion: &completion.PtsCompletion{AppID: &app, ArgsLen: -1, ConfigFile: &cmdr.ConfigFile},
}
cmd := &cobra.Command{
Use: "restart [<ptype>...]",
Args: cobra.ArbitraryArgs,
Example: "drycc pts restart web",
Short: i18n.T("Restart application process types"),
Long: i18n.T("Restart an application or process types"),
ValidArgsFunction: ptsArgsCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
flags.ptypes = args
return cmdr.PtsRestart(app, flags.ptypes, flags.confirm)
},
}
cmd.Flags().StringVar(&flags.confirm, "confirm", "", i18n.T(`To proceed, type "yes"`))
return cmd
}
// ptsScaleCommand
func ptsScaleCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
app string
scale []string // format like "web=5"
}
ptsSetArgsCompletion := completion.PtsSetArgsCompletion{
PtsCompletion: &completion.PtsCompletion{AppID: &app, ArgsLen: -1, ConfigFile: &cmdr.ConfigFile},
}
cmd := &cobra.Command{
Use: "scale <ptype>=<num>...",
Args: cobra.MinimumNArgs(1),
Example: template.CustomExample(
"drycc pts scale web=3",
map[string]string{
"<ptype>": i18n.T("The process name as defined in your Procfile"),
"<num>": i18n.T("The number of processes"),
},
),
Short: i18n.T("Scale process types of replicas"),
Long: i18n.T("Scales an application's processes by type"),
ValidArgsFunction: ptsSetArgsCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
flags.scale = args
return cmdr.PtsScale(app, flags.scale)
},
}
// shortcuts scale has not app flag
cmd.Flags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name for the application"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
return cmd
}
// ptsCleanCommand
func ptsCleanCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
ptypes []string
}
cmd := &cobra.Command{
Use: "clean <ptype>...",
Args: cobra.MinimumNArgs(1),
Example: template.CustomExample(
"drycc pts clean web",
map[string]string{
"<ptype>": i18n.T("The process name as defined in your Procfile"),
},
),
Short: i18n.T("Clean process types of not used"),
RunE: func(cmd *cobra.Command, args []string) error {
flags.ptypes = args
return cmdr.PtsClean(app, flags.ptypes)
},
}
return cmd
}