@@ -26,27 +26,63 @@ import (
2626)
2727
2828// list runs a request to list clones of an instance.
29- func list () func (* cli.Context ) error {
30- return func (cliCtx * cli.Context ) error {
31- dblabClient , err := commands .ClientByCLIContext (cliCtx )
32- if err != nil {
33- return err
34- }
29+ func list (cliCtx * cli.Context ) error {
30+ dblabClient , err := commands .ClientByCLIContext (cliCtx )
31+ if err != nil {
32+ return err
33+ }
3534
36- list , err := dblabClient .ListClones (cliCtx .Context )
37- if err != nil {
38- return err
39- }
35+ body , err := dblabClient .ListClonesRaw (cliCtx .Context )
36+ if err != nil {
37+ return err
38+ }
4039
41- commandResponse , err := json .MarshalIndent (list , "" , " " )
42- if err != nil {
43- return err
44- }
40+ defer func () { _ = body .Close () }()
4541
46- _ , err = fmt .Fprintln (cliCtx .App .Writer , string (commandResponse ))
42+ var viewCloneList * models.CloneListView
43+
44+ if err := json .NewDecoder (body ).Decode (& viewCloneList ); err != nil {
45+ return err
46+ }
4747
48+ commandResponse , err := json .MarshalIndent (viewCloneList .Clones , "" , " " )
49+ if err != nil {
4850 return err
4951 }
52+
53+ _ , err = fmt .Fprintln (cliCtx .App .Writer , string (commandResponse ))
54+
55+ return err
56+ }
57+
58+ // status runs a request to get clone info.
59+ func status (cliCtx * cli.Context ) error {
60+ dblabClient , err := commands .ClientByCLIContext (cliCtx )
61+ if err != nil {
62+ return err
63+ }
64+
65+ body , err := dblabClient .GetCloneRaw (cliCtx .Context , cliCtx .Args ().First ())
66+ if err != nil {
67+ return err
68+ }
69+
70+ defer func () { _ = body .Close () }()
71+
72+ var cloneView * models.CloneView
73+
74+ if err := json .NewDecoder (body ).Decode (& cloneView ); err != nil {
75+ return err
76+ }
77+
78+ commandResponse , err := json .MarshalIndent (cloneView , "" , " " )
79+ if err != nil {
80+ return err
81+ }
82+
83+ _ , err = fmt .Fprintln (cliCtx .App .Writer , string (commandResponse ))
84+
85+ return err
5086}
5187
5288// create runs a request to create a new clone.
@@ -85,7 +121,12 @@ func create(cliCtx *cli.Context) error {
85121 return err
86122 }
87123
88- commandResponse , err := json .MarshalIndent (clone , "" , " " )
124+ viewClone , err := convertCloneView (clone )
125+ if err != nil {
126+ return err
127+ }
128+
129+ commandResponse , err := json .MarshalIndent (viewClone , "" , " " )
89130 if err != nil {
90131 return err
91132 }
@@ -95,114 +136,103 @@ func create(cliCtx *cli.Context) error {
95136 return err
96137}
97138
98- // status runs a request to get clone info.
99- func status () func (* cli.Context ) error {
100- return func (cliCtx * cli.Context ) error {
101- dblabClient , err := commands .ClientByCLIContext (cliCtx )
102- if err != nil {
103- return err
104- }
105-
106- clone , err := dblabClient .GetClone (cliCtx .Context , cliCtx .Args ().First ())
107- if err != nil {
108- return err
109- }
139+ // update runs a request to update an existing clone.
140+ func update (cliCtx * cli.Context ) error {
141+ dblabClient , err := commands .ClientByCLIContext (cliCtx )
142+ if err != nil {
143+ return err
144+ }
110145
111- commandResponse , err := json .MarshalIndent (clone , "" , " " )
112- if err != nil {
113- return err
114- }
146+ updateRequest := types.CloneUpdateRequest {
147+ Protected : cliCtx .Bool ("protected" ),
148+ }
115149
116- _ , err = fmt . Fprintln ( cliCtx .App . Writer , string ( commandResponse ) )
150+ cloneID := cliCtx .Args (). First ( )
117151
152+ clone , err := dblabClient .UpdateClone (cliCtx .Context , cloneID , updateRequest )
153+ if err != nil {
118154 return err
119155 }
120- }
121156
122- // update runs a request to update an existing clone.
123- func update () func (* cli.Context ) error {
124- return func (cliCtx * cli.Context ) error {
125- dblabClient , err := commands .ClientByCLIContext (cliCtx )
126- if err != nil {
127- return err
128- }
129-
130- updateRequest := types.CloneUpdateRequest {
131- Protected : cliCtx .Bool ("protected" ),
132- }
157+ viewClone , err := convertCloneView (clone )
158+ if err != nil {
159+ return err
160+ }
133161
134- cloneID := cliCtx .Args ().First ()
162+ commandResponse , err := json .MarshalIndent (viewClone , "" , " " )
163+ if err != nil {
164+ return err
165+ }
135166
136- clone , err := dblabClient .UpdateClone (cliCtx .Context , cloneID , updateRequest )
137- if err != nil {
138- return err
139- }
167+ _ , err = fmt .Fprintln (cliCtx .App .Writer , string (commandResponse ))
140168
141- commandResponse , err := json .MarshalIndent (clone , "" , " " )
142- if err != nil {
143- return err
144- }
169+ return err
170+ }
145171
146- _ , err = fmt .Fprintln (cliCtx .App .Writer , string (commandResponse ))
172+ func convertCloneView (clone * models.Clone ) (* models.CloneView , error ) {
173+ data , err := json .Marshal (clone )
174+ if err != nil {
175+ return nil , err
176+ }
147177
148- return err
178+ var viewClone * models.CloneView
179+ if err = json .Unmarshal (data , & viewClone ); err != nil {
180+ return nil , err
149181 }
182+
183+ return viewClone , nil
150184}
151185
152186// reset runs a request to reset clone.
153- func reset () func (* cli.Context ) error {
154- return func (cliCtx * cli.Context ) error {
155- dblabClient , err := commands .ClientByCLIContext (cliCtx )
156- if err != nil {
157- return err
158- }
159-
160- cloneID := cliCtx .Args ().First ()
161- resetOptions := types.ResetCloneRequest {
162- Latest : cliCtx .Bool (cloneResetLatestFlag ),
163- SnapshotID : cliCtx .String (cloneResetSnapshotIDFlag ),
164- }
165-
166- if cliCtx .Bool ("async" ) {
167- err = dblabClient .ResetCloneAsync (cliCtx .Context , cloneID , resetOptions )
168- } else {
169- err = dblabClient .ResetClone (cliCtx .Context , cloneID , resetOptions )
170- }
187+ func reset (cliCtx * cli.Context ) error {
188+ dblabClient , err := commands .ClientByCLIContext (cliCtx )
189+ if err != nil {
190+ return err
191+ }
171192
172- if err != nil {
173- return err
174- }
193+ cloneID := cliCtx .Args ().First ()
194+ resetOptions := types.ResetCloneRequest {
195+ Latest : cliCtx .Bool (cloneResetLatestFlag ),
196+ SnapshotID : cliCtx .String (cloneResetSnapshotIDFlag ),
197+ }
175198
176- _ , err = fmt .Fprintf (cliCtx .App .Writer , "The clone has been successfully reset: %s\n " , cloneID )
199+ if cliCtx .Bool ("async" ) {
200+ err = dblabClient .ResetCloneAsync (cliCtx .Context , cloneID , resetOptions )
201+ } else {
202+ err = dblabClient .ResetClone (cliCtx .Context , cloneID , resetOptions )
203+ }
177204
205+ if err != nil {
178206 return err
179207 }
180- }
181208
182- // destroy runs a request to destroy clone.
183- func destroy () func (* cli.Context ) error {
184- return func (cliCtx * cli.Context ) error {
185- dblabClient , err := commands .ClientByCLIContext (cliCtx )
186- if err != nil {
187- return err
188- }
209+ _ , err = fmt .Fprintf (cliCtx .App .Writer , "The clone has been successfully reset: %s\n " , cloneID )
189210
190- cloneID := cliCtx .Args ().First ()
211+ return err
212+ }
191213
192- if cliCtx .Bool ("async" ) {
193- err = dblabClient .DestroyCloneAsync (cliCtx .Context , cloneID )
194- } else {
195- err = dblabClient .DestroyClone (cliCtx .Context , cloneID )
196- }
214+ // destroy runs a request to destroy clone.
215+ func destroy (cliCtx * cli.Context ) error {
216+ dblabClient , err := commands .ClientByCLIContext (cliCtx )
217+ if err != nil {
218+ return err
219+ }
197220
198- if err != nil {
199- return err
200- }
221+ cloneID := cliCtx .Args ().First ()
201222
202- _ , err = fmt .Fprintf (cliCtx .App .Writer , "The clone has been successfully destroyed: %s\n " , cloneID )
223+ if cliCtx .Bool ("async" ) {
224+ err = dblabClient .DestroyCloneAsync (cliCtx .Context , cloneID )
225+ } else {
226+ err = dblabClient .DestroyClone (cliCtx .Context , cloneID )
227+ }
203228
229+ if err != nil {
204230 return err
205231 }
232+
233+ _ , err = fmt .Fprintf (cliCtx .App .Writer , "The clone has been successfully destroyed: %s\n " , cloneID )
234+
235+ return err
206236}
207237
208238// startObservation runs a request to startObservation clone.
0 commit comments