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

Function project_init

atomic-cli/src/commands/rpc.rs:7251–7343  ·  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

7249/// client-side; the ONE repository mutation (add_remote origin) routes
7250/// through ManageRemotes so the command never opens redb directly.
7251pub fn project_init(args: &super::project::init::ProjectInit) -> CliResult<bool> {
7252 // Client-side: build the storage client (config + identity reads, no
7253 // redb) and run the server-side workspace/project creation exactly as
7254 // the local body does.
7255 let rt = tokio::runtime::Runtime::new().map_err(|e| {
7256 CliError::Internal(anyhow::anyhow!("Failed to create async runtime: {}", e))
7257 })?;
7258 let outcome = rt.block_on(async {
7259 let (client, org_slug) =
7260 crate::commands::client::build_client_with_org(args.org.as_deref(), None).await?;
7261 let workspace =
7262 crate::commands::client::resolve_workspace(&org_slug, args.workspace.as_deref(), None)?;
7263
7264 // Ensure the workspace exists — create it if necessary.
7265 // A 409 (Conflict) means it already exists, which is fine.
7266 match client.get_workspace(&workspace).await {
7267 Ok(_) => {}
7268 Err(_) => {
7269 let ws_req = atomic_remote::storage_types::CreateWorkspaceRequest {
7270 name: workspace.clone(),
7271 description: None,
7272 visibility: args.visibility,
7273 };
7274 match client.create_workspace(&ws_req).await {
7275 Ok(ws) => {
7276 print_success(&format!("Created workspace: {}", ws.slug));
7277 }
7278 Err(e) => {
7279 let msg = e.to_string();
7280 if msg.contains("409")
7281 || msg.contains("conflict")
7282 || msg.contains("Conflict")
7283 {
7284 print_info(&format!(
7285 "Workspace '{}' already exists, using it.",
7286 workspace
7287 ));
7288 } else {
7289 return Err(crate::commands::client::remote_err(e));
7290 }
7291 }
7292 }
7293 }
7294 }
7295
7296 let proj_req = atomic_remote::storage_types::CreateProjectRequest {
7297 name: args.name.clone(),
7298 description: args.description.clone(),
7299 default_view: "dev".to_string(),
7300 kind: args.kind.clone(),
7301 visibility: args.visibility,
7302 };
7303 let project = client
7304 .create_project(&workspace, &proj_req)
7305 .await
7306 .map_err(crate::commands::client::remote_err)?;
7307 let vcs_url = format!(
7308 "{}/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
openFunction · 0.85
print_next_stepsFunction · 0.85
get_workspaceMethod · 0.80
create_workspaceMethod · 0.80
create_projectMethod · 0.80
request_metaFunction · 0.70
cloneMethod · 0.45

Tested by

no test coverage detected