@@ -47,12 +47,18 @@ var (
4747 CHECK_TOPOLOGY_PLAYBOOK_STEPS = []int {
4848 playbook .CHECK_TOPOLOGY ,
4949 }
50+ SUPPORTED_DEPLOY_TYPES = []string {
51+ "production" ,
52+ "test" ,
53+ "develop" ,
54+ }
5055)
5156
5257type addOptions struct {
5358 name string
5459 descriotion string
5560 filename string
61+ deployType string
5662}
5763
5864func NewAddCommand (curveadm * cli.CurveAdm ) * cobra.Command {
@@ -63,6 +69,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
6369 Short : "Add cluster" ,
6470 Args : utils .ExactArgs (1 ),
6571 Example : ADD_EXAMPLE ,
72+ PreRunE : func (cmd * cobra.Command , args []string ) error {
73+ return checkAddOptions (cmd )
74+ },
6675 RunE : func (cmd * cobra.Command , args []string ) error {
6776 options .name = args [0 ]
6877 return runAdd (curveadm , options )
@@ -73,7 +82,7 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
7382 flags := cmd .Flags ()
7483 flags .StringVarP (& options .descriotion , "description" , "m" , "" , "Description for cluster" )
7584 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" )
7786 return cmd
7887}
7988
@@ -134,6 +143,19 @@ func checkTopology(curveadm *cli.CurveAdm, data string, options addOptions) erro
134143 return pb .Run ()
135144}
136145
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+
137159func runAdd (curveadm * cli.CurveAdm , options addOptions ) error {
138160 // 1) check wether cluster already exist
139161 name := options .name
@@ -163,7 +185,7 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
163185
164186 // 4) insert cluster (with topology) into database
165187 uuid := uuid .NewString ()
166- err = storage .InsertCluster (name , uuid , options .descriotion , data )
188+ err = storage .InsertCluster (name , uuid , options .descriotion , data , options . deployType )
167189 if err != nil {
168190 return errno .ERR_INSERT_CLUSTER_FAILED .E (err )
169191 }
0 commit comments