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:144–179  ·  view source on GitHub ↗

Remove references to a deleted org from the local global config. Returns the side effects performed so the caller can print appropriate hints. Specifically: - If `server.default_org == Some(slug)`, set it to `None` and hint. - Remove `server.default_workspaces[slug]` if present.

(deleted_slug: &str)

Source from the content-addressed store, hash-verified

142/// - If `server.default_org == Some(slug)`, set it to `None` and hint.
143/// - Remove `server.default_workspaces[slug]` if present.
144fn clean_up_local_config(deleted_slug: &str) -> CliResult<()> {
145 let mut config = GlobalConfig::load()
146 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load global config: {e}")))?;
147
148 let mut changed = false;
149 let was_default_org = config.server.default_org.as_deref() == Some(deleted_slug);
150 if was_default_org {
151 config.server.default_org = None;
152 changed = true;
153 }
154 if config
155 .server
156 .default_workspaces
157 .remove(deleted_slug)
158 .is_some()
159 {
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 3

print_hintFunction · 0.85
removeMethod · 0.65
saveMethod · 0.45

Tested by

no test coverage detected