@@ -13,7 +13,6 @@ import (
13
13
clustercmd "github.com/tarantool/tt/cli/cluster/cmd"
14
14
"github.com/tarantool/tt/cli/cmd/internal"
15
15
"github.com/tarantool/tt/cli/cmdcontext"
16
- "github.com/tarantool/tt/cli/modules"
17
16
"github.com/tarantool/tt/cli/replicaset"
18
17
"github.com/tarantool/tt/cli/running"
19
18
"github.com/tarantool/tt/cli/util"
@@ -141,19 +140,13 @@ func newClusterReplicasetCmd() *cobra.Command {
141
140
Aliases : []string {"rs" },
142
141
}
143
142
144
- promoteCmd := & cobra.Command {
143
+ promoteCmd := setupTtModuleCmd ( internalClusterReplicasetPromoteModule , & cobra.Command {
145
144
Use : "promote [-f] [flags] <URI> <INSTANCE_NAME>" ,
146
145
DisableFlagsInUseLine : true ,
147
146
Short : "Promote an instance" ,
148
147
Long : "Promote an instance\n \n " + clusterUriHelp ,
149
- Run : func (cmd * cobra.Command , args []string ) {
150
- cmdCtx .CommandName = cmd .Name ()
151
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
152
- internalClusterReplicasetPromoteModule , args )
153
- util .HandleCmdErr (cmd , err )
154
- },
155
- Args : cobra .ExactArgs (2 ),
156
- }
148
+ Args : cobra .ExactArgs (2 ),
149
+ })
157
150
promoteCmd .Flags ().StringVarP (& promoteCtx .Username , "username" , "u" , "" ,
158
151
"username (used as etcd/tarantool config storage credentials)" )
159
152
promoteCmd .Flags ().StringVarP (& promoteCtx .Password , "password" , "p" , "" ,
@@ -162,19 +155,13 @@ func newClusterReplicasetCmd() *cobra.Command {
162
155
"skip selecting a key for patching" )
163
156
integrity .RegisterWithIntegrityFlag (promoteCmd .Flags (), & clusterIntegrityPrivateKey )
164
157
165
- demoteCmd := & cobra.Command {
158
+ demoteCmd := setupTtModuleCmd ( internalClusterReplicasetDemoteModule , & cobra.Command {
166
159
Use : "demote [-f] [flags] <URI> <INSTANCE_NAME>" ,
167
160
DisableFlagsInUseLine : true ,
168
161
Short : "Demote an instance" ,
169
162
Long : "Demote an instance\n \n " + clusterUriHelp ,
170
- Run : func (cmd * cobra.Command , args []string ) {
171
- cmdCtx .CommandName = cmd .Name ()
172
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
173
- internalClusterReplicasetDemoteModule , args )
174
- util .HandleCmdErr (cmd , err )
175
- },
176
- Args : cobra .ExactArgs (2 ),
177
- }
163
+ Args : cobra .ExactArgs (2 ),
164
+ })
178
165
179
166
demoteCmd .Flags ().StringVarP (& demoteCtx .Username , "username" , "u" , "" ,
180
167
"username (used as etcd/tarantool config storage credentials)" )
@@ -184,19 +171,13 @@ func newClusterReplicasetCmd() *cobra.Command {
184
171
"skip selecting a key for patching" )
185
172
integrity .RegisterWithIntegrityFlag (demoteCmd .Flags (), & clusterIntegrityPrivateKey )
186
173
187
- expelCmd := & cobra.Command {
174
+ expelCmd := setupTtModuleCmd ( internalClusterReplicasetExpelModule , & cobra.Command {
188
175
Use : "expel [-f] [flags] <URI> <INSTANCE_NAME>" ,
189
176
DisableFlagsInUseLine : true ,
190
177
Short : "Expel an instance" ,
191
178
Long : "Expel an instance\n \n " + clusterUriHelp ,
192
- Run : func (cmd * cobra.Command , args []string ) {
193
- cmdCtx .CommandName = cmd .Name ()
194
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
195
- internalClusterReplicasetExpelModule , args )
196
- util .HandleCmdErr (cmd , err )
197
- },
198
- Args : cobra .ExactArgs (2 ),
199
- }
179
+ Args : cobra .ExactArgs (2 ),
180
+ })
200
181
201
182
expelCmd .Flags ().StringVarP (& expelCtx .Username , "username" , "u" , "" ,
202
183
"username (used as etcd/tarantool config storage credentials)" )
@@ -211,20 +192,14 @@ func newClusterReplicasetCmd() *cobra.Command {
211
192
Short : "Add or remove roles in cluster replicaset" ,
212
193
}
213
194
214
- addRolesCmd := & cobra.Command {
195
+ addRolesCmd := setupTtModuleCmd ( internalClusterReplicasetRolesAddModule , & cobra.Command {
215
196
Use : "add <URI> <ROLE_NAME> [flags]" ,
216
197
Short : "Add role to an instance, group or instance" ,
217
198
Long : "Add role to an instance, group or instance\n \n " + clusterUriHelp ,
218
- Run : func (cmd * cobra.Command , args []string ) {
219
- cmdCtx .CommandName = cmd .Name ()
220
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
221
- internalClusterReplicasetRolesAddModule , args )
222
- util .HandleCmdErr (cmd , err )
223
- },
224
199
Example : "tt cluster replicaset roles add http://user:pass@localhost:3301" +
225
200
" roles.metrics-export --instance_name master" ,
226
201
Args : cobra .ExactArgs (2 ),
227
- }
202
+ })
228
203
229
204
addRolesCmd .Flags ().StringVarP (& rolesChangeCtx .ReplicasetName , "replicaset" , "r" , "" ,
230
205
"name of a target replicaset" )
@@ -243,20 +218,14 @@ func newClusterReplicasetCmd() *cobra.Command {
243
218
"skip selecting a key for patching" )
244
219
integrity .RegisterWithIntegrityFlag (addRolesCmd .Flags (), & clusterIntegrityPrivateKey )
245
220
246
- removeRolesCmd := & cobra.Command {
221
+ removeRolesCmd := setupTtModuleCmd ( internalClusterReplicasetRolesRemoveModule , & cobra.Command {
247
222
Use : "remove <URI> <ROLE_NAME> [flags]" ,
248
223
Short : "Remove role from instance, group, instance or globally" ,
249
224
Long : "Remove role from instance, group, instance or globally\n \n " + clusterUriHelp ,
250
- Run : func (cmd * cobra.Command , args []string ) {
251
- cmdCtx .CommandName = cmd .Name ()
252
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
253
- internalClusterReplicasetRolesRemoveModule , args )
254
- util .HandleCmdErr (cmd , err )
255
- },
256
225
Example : "tt cluster replicaset roles remove http://user:pass@localhost:3301" +
257
226
" roles.metrics-export --instance_name master" ,
258
227
Args : cobra .ExactArgs (2 ),
259
- }
228
+ })
260
229
261
230
removeRolesCmd .Flags ().StringVarP (& rolesChangeCtx .ReplicasetName , "replicaset" , "r" , "" ,
262
231
"name of a target replicaset" )
@@ -293,20 +262,14 @@ func newClusterFailoverCmd() *cobra.Command {
293
262
Aliases : []string {"fo" },
294
263
}
295
264
296
- switchCmd := & cobra.Command {
265
+ switchCmd := setupTtModuleCmd ( internalClusterFailoverSwitchModule , & cobra.Command {
297
266
Use : "switch <URI> <INSTANCE_NAME> [flags]" ,
298
267
DisableFlagsInUseLine : true ,
299
268
Short : "Switch master instance" ,
300
269
Long : "Switch master instance\n \n " + failoverUriHelp ,
301
270
Example : "tt cluster failover switch http://localhost:2379/app instance_name" ,
302
- Run : func (cmd * cobra.Command , args []string ) {
303
- cmdCtx .CommandName = cmd .Name ()
304
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
305
- internalClusterFailoverSwitchModule , args )
306
- util .HandleCmdErr (cmd , err )
307
- },
308
- Args : cobra .ExactArgs (2 ),
309
- }
271
+ Args : cobra .ExactArgs (2 ),
272
+ })
310
273
311
274
switchCmd .Flags ().StringVarP (& switchCtx .Username , "username" , "u" , "" ,
312
275
"username (used as etcd credentials)" )
@@ -317,19 +280,13 @@ func newClusterFailoverCmd() *cobra.Command {
317
280
switchCmd .Flags ().BoolVarP (& switchCtx .Wait , "wait" , "w" , false ,
318
281
"wait for the command to complete execution" )
319
282
320
- switchStatusCmd := & cobra.Command {
283
+ switchStatusCmd := setupTtModuleCmd ( internalClusterFailoverSwitchStatusModule , & cobra.Command {
321
284
Use : "switch-status <URI> <TASK_ID>" ,
322
285
DisableFlagsInUseLine : true ,
323
286
Short : "Show master switching status" ,
324
287
Long : "Show master switching status\n \n " + failoverUriHelp ,
325
- Run : func (cmd * cobra.Command , args []string ) {
326
- cmdCtx .CommandName = cmd .Name ()
327
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
328
- internalClusterFailoverSwitchStatusModule , args )
329
- util .HandleCmdErr (cmd , err )
330
- },
331
- Args : cobra .ExactArgs (2 ),
332
- }
288
+ Args : cobra .ExactArgs (2 ),
289
+ })
333
290
334
291
cmd .AddCommand (switchCmd )
335
292
cmd .AddCommand (switchStatusCmd )
@@ -343,7 +300,7 @@ func NewClusterCmd() *cobra.Command {
343
300
Short : "Manage cluster configuration" ,
344
301
}
345
302
346
- show := & cobra.Command {
303
+ show := setupTtModuleCmd ( internalClusterShowModule , & cobra.Command {
347
304
Use : "show (<APP_NAME> | <APP_NAME:INSTANCE_NAME> | <URI>)" ,
348
305
Short : "Show a cluster configuration" ,
349
306
Long : "Show a cluster configuration for an application, instance," +
@@ -352,12 +309,6 @@ func NewClusterCmd() *cobra.Command {
352
309
" tt cluster show application_name:instance_name\n " +
353
310
" tt cluster show https://user:pass@localhost:2379/tt\n " +
354
311
" tt cluster show https://user:pass@localhost:2379/tt?name=instance" ,
355
- Run : func (cmd * cobra.Command , args []string ) {
356
- cmdCtx .CommandName = cmd .Name ()
357
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
358
- internalClusterShowModule , args )
359
- util .HandleCmdErr (cmd , err )
360
- },
361
312
Args : cobra .ExactArgs (1 ),
362
313
ValidArgsFunction : func (
363
314
cmd * cobra.Command ,
@@ -371,7 +322,7 @@ func NewClusterCmd() *cobra.Command {
371
322
running .ExtractActiveAppNames ,
372
323
running .ExtractActiveInstanceNames )
373
324
},
374
- }
325
+ })
375
326
show .Flags ().StringVarP (& showCtx .Username , "username" , "u" , "" ,
376
327
"username (used as etcd credentials only)" )
377
328
show .Flags ().StringVarP (& showCtx .Password , "password" , "p" , "" ,
@@ -380,7 +331,7 @@ func NewClusterCmd() *cobra.Command {
380
331
"validate the configuration" )
381
332
clusterCmd .AddCommand (show )
382
333
383
- publish := & cobra.Command {
334
+ publish := setupTtModuleCmd ( internalClusterPublishModule , & cobra.Command {
384
335
Use : "publish (<APP_NAME> | <APP_NAME:INSTANCE_NAME> | <URI>) file" ,
385
336
Short : "Publish a cluster configuration" ,
386
337
Long : "Publish an application or an instance configuration to a cluster " +
@@ -399,12 +350,6 @@ func NewClusterCmd() *cobra.Command {
399
350
" tt cluster publish --group group --replicaset replicaset " +
400
351
"https://user:pass@localhost:2379/tt?name=instance " +
401
352
"instance.yaml" ,
402
- Run : func (cmd * cobra.Command , args []string ) {
403
- cmdCtx .CommandName = cmd .Name ()
404
- err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
405
- internalClusterPublishModule , args )
406
- util .HandleCmdErr (cmd , err )
407
- },
408
353
Args : cobra .ExactArgs (2 ),
409
354
ValidArgsFunction : func (
410
355
cmd * cobra.Command ,
@@ -415,7 +360,7 @@ func NewClusterCmd() *cobra.Command {
415
360
running .ExtractActiveAppNames ,
416
361
running .ExtractActiveInstanceNames )
417
362
},
418
- }
363
+ })
419
364
publish .Flags ().StringVarP (& publishCtx .Username , "username" , "u" , "" ,
420
365
"username (used as etcd credentials only)" )
421
366
publish .Flags ().StringVarP (& publishCtx .Password , "password" , "p" , "" ,
0 commit comments