(&self)
| 67 | |
| 68 | impl Command for WorkspaceDelete { |
| 69 | fn run(&self) -> CliResult<()> { |
| 70 | let rt = tokio::runtime::Runtime::new() |
| 71 | .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; |
| 72 | |
| 73 | rt.block_on(async { |
| 74 | let (client, org_slug) = build_client_with_org(self.org.as_deref(), None).await?; |
| 75 | |
| 76 | // `--force` skips both the precheck and confirmation. |
| 77 | if !self.force { |
| 78 | // Check that the workspace exists before prompting. |
| 79 | client.get_workspace(&self.slug).await.map_err(remote_err)?; |
| 80 | |
| 81 | print_warning(&format!( |
| 82 | "This will permanently delete workspace '{}' and all its projects.", |
| 83 | self.slug |
| 84 | )); |
| 85 | |
| 86 | let confirmed = dialoguer::Confirm::new() |
| 87 | .with_prompt("Are you sure?") |
| 88 | .default(false) |
| 89 | .interact() |
| 90 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Prompt failed: {}", e)))?; |
| 91 | |
| 92 | if !confirmed { |
| 93 | print_error("Cancelled."); |
| 94 | return Err(CliError::Cancelled); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | client |
| 99 | .delete_workspace(&self.slug) |
| 100 | .await |
| 101 | .map_err(remote_err)?; |
| 102 | |
| 103 | print_success(&format!("Deleted workspace: {}", self.slug)); |
| 104 | |
| 105 | // If this workspace was the default for the org we just operated |
| 106 | // in, remove the stale entry so subsequent commands don't hit a |
| 107 | // confusing 404. Server-side deletion succeeded; config cleanup |
| 108 | // is best-effort. |
| 109 | if let Err(e) = clean_up_local_config(&org_slug, &self.slug) { |
| 110 | log::warn!("Failed to clean up local config after workspace delete: {e}"); |
| 111 | } |
| 112 | |
| 113 | Ok(()) |
| 114 | }) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /// Remove a deleted workspace from `[server.default_workspaces]` if it was |
nothing calls this directly
no test coverage detected