MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / clean_up_local_config

Function clean_up_local_config

atomic-cli/src/commands/org/delete.rs:145–179  ·  view source on GitHub ↗

Remove references to a deleted org from the local global config. Operates on the **active** server profile (the same one reads/writes resolve to), so cleanup stays consistent when a named profile is active. Specifically: - If `default_org == Some(slug)`, set it to `None` and hint. - Remove `default_workspaces[slug]` if present.

(deleted_slug: &str)

Source from the content-addressed store, hash-verified

143/// - If `default_org == Some(slug)`, set it to `None` and hint.
144/// - Remove `default_workspaces[slug]` if present.
145fn clean_up_local_config(deleted_slug: &str) -> CliResult<()> {
146 let mut config = GlobalConfig::load()
147 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load global config: {e}")))?;
148
149 let (server, _name) = config
150 .resolve_server_mut(None)
151 .map_err(|e| CliError::Internal(anyhow::anyhow!("{e}")))?;
152
153 let mut changed = false;
154 let was_default_org = server.default_org.as_deref() == Some(deleted_slug);
155 if was_default_org {
156 server.default_org = None;
157 changed = true;
158 }
159 if server.default_workspaces.remove(deleted_slug).is_some() {
160 changed = true;
161 }
162
163 if !changed {
164 return Ok(());
165 }
166
167 config
168 .save()
169 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save global config: {e}")))?;
170
171 if was_default_org {
172 print_hint(&format!(
173 "Default org was '{deleted_slug}' — run 'atomic org set <slug>' \
174 to pick a new one."
175 ));
176 }
177
178 Ok(())
179}
180
181#[cfg(test)]
182mod tests {

Callers 1

executeMethod · 0.70

Calls 4

print_hintFunction · 0.85
resolve_server_mutMethod · 0.80
removeMethod · 0.65
saveMethod · 0.45

Tested by

no test coverage detected