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:136–171  ·  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

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

Callers 1

executeMethod · 0.70

Calls 3

print_hintFunction · 0.85
removeMethod · 0.65
saveMethod · 0.45

Tested by

no test coverage detected