@@ -219,20 +219,51 @@ def destroy(
219219 setup_identifier : str = typer .Argument (
220220 ..., help = "The ID or name of the setup. Names take precedence."
221221 ),
222+ wait : Optional [bool ] = typer .Option (
223+ default = False , help = "Wait for the destroy job to complete"
224+ ),
222225) -> None :
223226 """
224227 Destroy the setup with the specified given ID or name.
225228 """
226229
227230 try :
228231 setup = get_setup (setup_identifier )
229- setup_client .destroy (setup ["id" ])
232+ job = setup_client .destroy (setup ["id" ])
230233
231234 display_success_message (f"Setup { setup ['id' ]} has been queued for destruction" )
232235 except Exception as error :
233236 display_error_message (error )
234237 raise typer .Abort ()
235238
239+ destruction_scheduled_message = (
240+ f"Setup { setup_identifier } has been queued for destruction"
241+ )
242+
243+ if not wait :
244+ display_success_message (destruction_scheduled_message )
245+ return
246+
247+ print (f"{ destruction_scheduled_message } \n " )
248+
249+ try :
250+ display_job_logs (job ["id" ])
251+ except websockets .exceptions .ConnectionClosed :
252+ job = job_client .retrieve (job ["id" ])
253+
254+ match job ["status" ]:
255+ case "Initialized" :
256+ display_success_message (
257+ f"Setup { setup_identifier } has been destroyed successfully"
258+ )
259+ case "Failed" :
260+ display_error_message (
261+ f"Setup { setup_identifier } could not be destroyed"
262+ )
263+ case _:
264+ print (f"Setup { setup_identifier } is in status { job ['status' ]} " )
265+ return
266+
236267
237268def get_setup (setup_identifier : str ) -> Optional [Dict [str , Any ]]:
238269 """
0 commit comments