@@ -3,7 +3,6 @@ package cmd
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "os"
7
6
"regexp"
8
7
"strings"
9
8
51
50
52
51
chosenReplicasetAliases []string
53
52
lsnTimeout int
54
- downgradeVersion string
55
53
56
54
replicasetUriHelp = " The URI can be specified in the following formats:\n " +
57
55
" * [tcp://][username:password@][host:port]\n " +
@@ -90,33 +88,33 @@ func newUpgradeCmd() *cobra.Command {
90
88
91
89
// newDowngradeCmd creates a "replicaset downgrade" command.
92
90
func newDowngradeCmd () * cobra.Command {
91
+ validateVersion := func (i int ) cobra.PositionalArgs {
92
+ return func (cmd * cobra.Command , args []string ) error {
93
+ var versionPattern = regexp .MustCompile (`^\d+\.\d+\.\d+$` )
94
+ if args [i ] == "" {
95
+ return errors .New ("need to specify the version to downgrade to" )
96
+ } else if ! versionPattern .MatchString (args [i ]) {
97
+ return errors .New ("version must be in the format " +
98
+ "'x.x.x', where x is a number" )
99
+ }
100
+ return nil
101
+ }
102
+ }
103
+
93
104
cmd := & cobra.Command {
94
- Use : "downgrade (<APP_NAME> | <URI>) [flags]\n \n " +
105
+ Use : "downgrade (<APP_NAME> | <URI>) VERSION [flags]\n \n " +
95
106
replicasetUriHelp ,
96
107
DisableFlagsInUseLine : true ,
97
108
Short : "Downgrade tarantool cluster" ,
98
109
Long : "Downgrade tarantool cluster.\n \n " +
99
110
libconnect .EnvCredentialsHelp + "\n \n " ,
100
111
Run : func (cmd * cobra.Command , args []string ) {
101
- var versionPattern = regexp .MustCompile (`^\d+\.\d+\.\d+$` )
102
- if downgradeVersion == "" {
103
- err := errors .New ("need to specify the version to downgrade " +
104
- "use --version (-v) option" )
105
- util .HandleCmdErr (cmd , err )
106
- os .Exit (1 )
107
- } else if ! versionPattern .MatchString (downgradeVersion ) {
108
- err := errors .New ("--version (-v) must be in the format " +
109
- "'x.x.x', where x is a number" )
110
- util .HandleCmdErr (cmd , err )
111
- os .Exit (1 )
112
- }
113
-
114
112
cmdCtx .CommandName = cmd .Name ()
115
113
err := modules .RunCmd (& cmdCtx , cmd .CommandPath (), & modulesInfo ,
116
114
internalReplicasetDowngradeModule , args )
117
115
util .HandleCmdErr (cmd , err )
118
116
},
119
- Args : cobra .ExactArgs (1 ),
117
+ Args : cobra .MatchAll ( cobra . ExactArgs (2 ), validateVersion ( 1 ) ),
120
118
}
121
119
122
120
cmd .Flags ().StringArrayVarP (& chosenReplicasetAliases , "replicaset" , "r" ,
@@ -125,9 +123,6 @@ func newDowngradeCmd() *cobra.Command {
125
123
cmd .Flags ().IntVarP (& lsnTimeout , "timeout" , "t" , 5 ,
126
124
"timeout for waiting the LSN synchronization (in seconds)" )
127
125
128
- cmd .Flags ().StringVarP (& downgradeVersion , "version" , "v" , "" ,
129
- "version to downgrade the schema to" )
130
-
131
126
addOrchestratorFlags (cmd )
132
127
addTarantoolConnectFlags (cmd )
133
128
return cmd
@@ -608,8 +603,11 @@ func internalReplicasetUpgradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) e
608
603
609
604
// internalReplicasetDowngradeModule is a "upgrade" command for the replicaset module.
610
605
func internalReplicasetDowngradeModule (cmdCtx * cmdcontext.CmdCtx , args []string ) error {
606
+ target := args [0 ]
607
+ downgradeVersion := args [1 ]
608
+
611
609
var ctx replicasetCtx
612
- if err := replicasetFillCtx (cmdCtx , & ctx , args [ 0 ] , false ); err != nil {
610
+ if err := replicasetFillCtx (cmdCtx , & ctx , target , false ); err != nil {
613
611
return err
614
612
}
615
613
if ctx .IsInstanceConnect {
@@ -625,7 +623,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
625
623
SslCiphers : replicasetSslCiphers ,
626
624
}
627
625
var connOpts connector.ConnectOpts
628
- connOpts , _ = resolveConnectOpts (cmdCtx , cliOpts , & connectCtx , args [ 0 ] )
626
+ connOpts , _ = resolveConnectOpts (cmdCtx , cliOpts , & connectCtx , target )
629
627
630
628
return replicasetcmd .Downgrade (replicasetcmd.DiscoveryCtx {
631
629
IsApplication : ctx .IsApplication ,
0 commit comments