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

Function project_init

atomic-cli/src/commands/rpc.rs:7334–7426  ·  view source on GitHub ↗

`atomic project init` — the server-side project creation (the management StorageClient built from the global config + the identity store — config/auth reads, not redb, per the push/pull ruling) stays client-side; the ONE repository mutation (add_remote origin) routes through ManageRemotes so the command never opens redb directly.

(args: &super::project::init::ProjectInit)

Source from the content-addressed store, hash-verified

7332/// client-side; the ONE repository mutation (add_remote origin) routes
7333/// through ManageRemotes so the command never opens redb directly.
7334pub fn project_init(args: &super::project::init::ProjectInit) -> CliResult<bool> {
7335 // Client-side: build the storage client (config + identity reads, no
7336 // redb) and run the server-side workspace/project creation exactly as
7337 // the local body does.
7338 let rt = tokio::runtime::Runtime::new().map_err(|e| {
7339 CliError::Internal(anyhow::anyhow!("Failed to create async runtime: {}", e))
7340 })?;
7341 let outcome = rt.block_on(async {
7342 let (client, org_slug) =
7343 crate::commands::client::build_client_with_org(args.org.as_deref(), None).await?;
7344 let workspace =
7345 crate::commands::client::resolve_workspace(&org_slug, args.workspace.as_deref(), None)?;
7346
7347 // Ensure the workspace exists — create it if necessary.
7348 // A 409 (Conflict) means it already exists, which is fine.
7349 match client.get_workspace(&workspace).await {
7350 Ok(_) => {}
7351 Err(_) => {
7352 let ws_req = atomic_remote::storage_types::CreateWorkspaceRequest {
7353 name: workspace.clone(),
7354 description: None,
7355 visibility: args.visibility,
7356 };
7357 match client.create_workspace(&ws_req).await {
7358 Ok(ws) => {
7359 print_success(&format!("Created workspace: {}", ws.slug));
7360 }
7361 Err(e) => {
7362 let msg = e.to_string();
7363 if msg.contains("409")
7364 || msg.contains("conflict")
7365 || msg.contains("Conflict")
7366 {
7367 print_info(&format!(
7368 "Workspace '{}' already exists, using it.",
7369 workspace
7370 ));
7371 } else {
7372 return Err(crate::commands::client::remote_err(e));
7373 }
7374 }
7375 }
7376 }
7377 }
7378
7379 let proj_req = atomic_remote::storage_types::CreateProjectRequest {
7380 name: args.name.clone(),
7381 description: args.description.clone(),
7382 default_view: "dev".to_string(),
7383 kind: args.kind.clone(),
7384 visibility: args.visibility,
7385 };
7386 let project = client
7387 .create_project(&workspace, &proj_req)
7388 .await
7389 .map_err(crate::commands::client::remote_err)?;
7390 let vcs_url = format!(
7391 "{}/workspaces/{}/projects/{}/code",

Callers 1

runMethod · 0.85

Calls 14

build_client_with_orgFunction · 0.85
resolve_workspaceFunction · 0.85
print_successFunction · 0.85
print_infoFunction · 0.85
remote_errFunction · 0.85
print_next_stepsFunction · 0.85
get_workspaceMethod · 0.80
create_workspaceMethod · 0.80
create_projectMethod · 0.80
request_metaFunction · 0.70
openFunction · 0.50
cloneMethod · 0.45

Tested by

no test coverage detected