Resolve the org slug for a command, with fallback to the configured default. This variant uses the *active* server's `default_org` so that per-server org defaults are respected. Resolution order: 1. `--org` override (if `Some(non-empty)`) 2. `server.default_org` from the resolved server profile 3. The default identity's personal org (the identity name), so commands always target the tenant assoc
(
org_override: Option<&str>,
server: &atomic_config::ServerConfig,
)
| 244 | /// An explicit empty string (`--org ""`) is an error: the user asked for "no |
| 245 | /// org" which never makes sense. |
| 246 | pub fn resolve_org_with_server( |
| 247 | org_override: Option<&str>, |
| 248 | server: &atomic_config::ServerConfig, |
| 249 | ) -> CliResult<String> { |
| 250 | if let Some(s) = org_override { |
| 251 | if s.is_empty() { |
| 252 | return Err(CliError::InvalidArgument { |
| 253 | message: "Organization slug cannot be empty.".to_string(), |
| 254 | }); |
| 255 | } |
| 256 | return Ok(s.to_string()); |
| 257 | } |
| 258 | |
| 259 | if let Some(org) = &server.default_org { |
| 260 | return Ok(org.clone()); |
| 261 | } |
| 262 | |
| 263 | // Fall back to the personal org of the identity this server authenticates |
| 264 | // as. Registration seeds the personal org slug from the identity name, so |
| 265 | // the identity name is the correct default until the user runs |
| 266 | // `atomic org set` to switch to a team org. |
| 267 | let identity = resolve_identity_for_server(server).map_err(|_| CliError::InvalidArgument { |
| 268 | message: "No organization specified.\n \ |
| 269 | Use --org or set a default with: atomic org set <slug>" |
| 270 | .to_string(), |
| 271 | })?; |
| 272 | Ok(identity.name) |
| 273 | } |
| 274 | |
| 275 | /// Resolve the org slug for callers that don't already hold a server config. |
| 276 | /// |
no test coverage detected