MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / add_server

Method add_server

atomic-cli/src/commands/server/mod.rs:228–291  ·  view source on GitHub ↗

Add a new server profile.

(&self, add: &ServerAdd)

Source from the content-addressed store, hash-verified

226
227 /// Add a new server profile.
228 fn add_server(&self, add: &ServerAdd) -> CliResult<()> {
229 if !add.url.contains("://") {
230 return Err(CliError::InvalidArgument {
231 message: format!(
232 "Invalid URL '{}': must include a scheme (e.g. https://)",
233 add.url
234 ),
235 });
236 }
237
238 let mut config = GlobalConfig::load()
239 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load config: {}", e)))?;
240
241 if config.servers.contains_key(&add.name) {
242 return Err(CliError::InvalidArgument {
243 message: format!(
244 "Server profile '{}' already exists. \
245 Use 'atomic server set-identity' or 'atomic server remove' to modify it.",
246 add.name
247 ),
248 });
249 }
250
251 let profile = ServerConfig {
252 url: Some(add.url.trim_end_matches('/').to_string()),
253 default_org: add.org.clone(),
254 default_workspaces: std::collections::BTreeMap::new(),
255 identity: add.identity.clone(),
256 // Auto-detected at registration; manual profiles default to
257 // multi-tenant URL semantics.
258 single_tenant: false,
259 };
260
261 config.servers.insert(add.name.clone(), profile);
262
263 if add.set_default {
264 config.default_server = Some(add.name.clone());
265 }
266
267 config
268 .save()
269 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save config: {}", e)))?;
270
271 print_success(&format!("Server profile '{}' added", add.name));
272 println!(" URL: {}", add.url);
273 if let Some(ref org) = add.org {
274 println!(" Org: {}", org);
275 }
276 if let Some(ref identity) = add.identity {
277 println!(" Identity: {}", identity);
278 }
279 if add.set_default {
280 println!();
281 print_success(&format!("'{}' is now the active server", add.name));
282 } else {
283 println!();
284 print_hint(&format!(
285 "To make this your default: atomic server set {}",

Callers 1

runMethod · 0.80

Calls 7

print_successFunction · 0.85
print_hintFunction · 0.85
contains_keyMethod · 0.80
containsMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected