Derive a short profile name from a server URL. `https://staging.atomic.storage` → `"staging"` `https://atomic.storage` → `"atomic-storage"` (no subdomain) `http://localhost:8080` → `"localhost"`
(server_url: &str)
| 334 | /// `https://atomic.storage` → `"atomic-storage"` (no subdomain) |
| 335 | /// `http://localhost:8080` → `"localhost"` |
| 336 | fn derive_profile_name(server_url: &str) -> Option<String> { |
| 337 | let url = url::Url::parse(server_url).ok()?; |
| 338 | let host = url.host_str()?; |
| 339 | |
| 340 | // If the host has a subdomain, use that as the profile name. |
| 341 | if let Some(dot) = host.find('.') { |
| 342 | let label = &host[..dot]; |
| 343 | if !label.is_empty() && label != "www" { |
| 344 | return Some(label.to_string()); |
| 345 | } |
| 346 | // No useful subdomain — fall through to full host slug. |
| 347 | } |
| 348 | |
| 349 | // Slug the host: replace dots and colons with hyphens, strip port. |
| 350 | let host_no_port = host.split(':').next().unwrap_or(host); |
| 351 | let slug = host_no_port.replace('.', "-"); |
| 352 | if slug.is_empty() { |
| 353 | None |
| 354 | } else { |
| 355 | Some(slug) |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | #[cfg(test)] |
| 360 | mod tests { |