When an identity becomes the active default, automatically activate the server profile bound to it (if any). Looks for a named profile in `~/.atomic/config.toml` whose `identity` field matches `identity_name`. If found, sets `default_server` to that profile name and saves the config. Emits a hint so the user knows the server switched alongside the identity. This is intentionally non-fatal: if th
(identity_name: &str)
| 434 | /// a debug log is emitted and the command still succeeds — the identity |
| 435 | /// switch itself is the important operation. |
| 436 | pub fn activate_server_for_identity(identity_name: &str) { |
| 437 | let mut config = match GlobalConfig::load() { |
| 438 | Ok(c) => c, |
| 439 | Err(e) => { |
| 440 | log::debug!("Could not load config for server auto-activation: {}", e); |
| 441 | return; |
| 442 | } |
| 443 | }; |
| 444 | |
| 445 | // Find a named server profile whose identity binding matches. |
| 446 | let matching_profile = config |
| 447 | .servers |
| 448 | .iter() |
| 449 | .find(|(_, srv)| srv.identity.as_deref() == Some(identity_name)) |
| 450 | .map(|(name, _)| name.clone()); |
| 451 | |
| 452 | if let Some(profile_name) = matching_profile { |
| 453 | // Only update + print if it's actually changing. |
| 454 | if config.default_server.as_deref() != Some(&profile_name) { |
| 455 | config.default_server = Some(profile_name.clone()); |
| 456 | if let Err(e) = config.save() { |
| 457 | log::debug!("Could not save config for server auto-activation: {}", e); |
| 458 | return; |
| 459 | } |
| 460 | crate::output::print_hint(&format!( |
| 461 | "Server profile '{}' activated (bound to identity '{}')", |
| 462 | profile_name, identity_name |
| 463 | )); |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | /// Load a named identity, or the store default when no name is given. |
| 469 | /// |