Remove a deleted workspace from the active server profile's `default_workspaces` if it was the configured default for its org. Operates on the **active** server profile (the same one `atomic workspace set` writes to) so cleanup stays consistent when a named profile is active.
(org_slug: &str, deleted_workspace: &str)
| 122 | /// `atomic workspace set` writes to) so cleanup stays consistent when a |
| 123 | /// named profile is active. |
| 124 | fn clean_up_local_config(org_slug: &str, deleted_workspace: &str) -> CliResult<()> { |
| 125 | let mut config = GlobalConfig::load() |
| 126 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load global config: {e}")))?; |
| 127 | |
| 128 | let (server, _name) = config |
| 129 | .resolve_server_mut(None) |
| 130 | .map_err(|e| CliError::Internal(anyhow::anyhow!("{e}")))?; |
| 131 | |
| 132 | let was_default = server |
| 133 | .default_workspaces |
| 134 | .get(org_slug) |
| 135 | .map(|v| v == deleted_workspace) |
| 136 | .unwrap_or(false); |
| 137 | |
| 138 | if !was_default { |
| 139 | return Ok(()); |
| 140 | } |
| 141 | |
| 142 | server.default_workspaces.remove(org_slug); |
| 143 | config |
| 144 | .save() |
| 145 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save global config: {e}")))?; |
| 146 | |
| 147 | print_hint(&format!( |
| 148 | "Default workspace for '{org_slug}' was '{deleted_workspace}' — \ |
| 149 | run 'atomic workspace set <slug>' to pick a new one." |
| 150 | )); |
| 151 | |
| 152 | Ok(()) |
| 153 | } |
| 154 | |
| 155 | #[cfg(test)] |
| 156 | mod tests { |
no test coverage detected