@@ -47,12 +47,18 @@ var (
47
47
CHECK_TOPOLOGY_PLAYBOOK_STEPS = []int {
48
48
playbook .CHECK_TOPOLOGY ,
49
49
}
50
+ SUPPORTED_DEPLOY_TYPES = []string {
51
+ "production" ,
52
+ "test" ,
53
+ "develop" ,
54
+ }
50
55
)
51
56
52
57
type addOptions struct {
53
58
name string
54
- descriotion string
59
+ description string
55
60
filename string
61
+ deployType string
56
62
}
57
63
58
64
func NewAddCommand (curveadm * cli.CurveAdm ) * cobra.Command {
@@ -63,6 +69,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
63
69
Short : "Add cluster" ,
64
70
Args : utils .ExactArgs (1 ),
65
71
Example : ADD_EXAMPLE ,
72
+ PreRunE : func (cmd * cobra.Command , args []string ) error {
73
+ return checkAddOptions (cmd )
74
+ },
66
75
RunE : func (cmd * cobra.Command , args []string ) error {
67
76
options .name = args [0 ]
68
77
return runAdd (curveadm , options )
@@ -71,9 +80,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
71
80
}
72
81
73
82
flags := cmd .Flags ()
74
- flags .StringVarP (& options .descriotion , "description" , "m" , "" , "Description for cluster" )
83
+ flags .StringVarP (& options .description , "description" , "m" , "" , "Description for cluster" )
75
84
flags .StringVarP (& options .filename , "topology" , "f" , "" , "Specify the path of topology file" )
76
-
85
+ flags . StringVar ( & options . deployType , "type" , "develop" , "Specify the type of cluster" )
77
86
return cmd
78
87
}
79
88
@@ -134,6 +143,19 @@ func checkTopology(curveadm *cli.CurveAdm, data string, options addOptions) erro
134
143
return pb .Run ()
135
144
}
136
145
146
+ func checkAddOptions (cmd * cobra.Command ) error {
147
+ deployType , err := cmd .Flags ().GetString ("deploy-type" )
148
+ if err != nil {
149
+ return err
150
+ }
151
+ for _ , t := range SUPPORTED_DEPLOY_TYPES {
152
+ if deployType == t {
153
+ return nil
154
+ }
155
+ }
156
+ return errno .ERR_UNSUPPORT_DEPLOY_TYPE .F ("deploy type: %s" , deployType )
157
+ }
158
+
137
159
func runAdd (curveadm * cli.CurveAdm , options addOptions ) error {
138
160
// 1) check wether cluster already exist
139
161
name := options .name
@@ -163,7 +185,7 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
163
185
164
186
// 4) insert cluster (with topology) into database
165
187
uuid := uuid .NewString ()
166
- err = storage .InsertCluster (name , uuid , options .descriotion , data )
188
+ err = storage .InsertCluster (name , uuid , options .description , data , options . deployType )
167
189
if err != nil {
168
190
return errno .ERR_INSERT_CLUSTER_FAILED .E (err )
169
191
}
0 commit comments