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

Method execute

atomic-cli/src/commands/project/init.rs:116–208  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

114
115impl ProjectInit {
116 async fn execute(&self) -> CliResult<()> {
117 // 1. Ensure we're inside an Atomic repository.
118 let repo_root = find_repository_root()?;
119 let repo = Repository::open(&repo_root).map_err(|e| match e {
120 atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound {
121 searched_path: path.into(),
122 },
123 other => CliError::Repository(other),
124 })?;
125
126 // 2. Build the storage client and resolve the workspace.
127 let (client, org_slug) = build_client_with_org(self.org.as_deref(), None).await?;
128 let workspace = resolve_workspace(&org_slug, self.workspace.as_deref(), None)?;
129
130 // 3. Ensure the workspace exists — create it if necessary.
131 // A 409 (Conflict) means it already exists, which is fine.
132 match client.get_workspace(&workspace).await {
133 Ok(_ws) => {
134 // Already exists — nothing to do.
135 }
136 Err(_) => {
137 // Try to create it. If the server returns 409 we ignore it.
138 let ws_req = CreateWorkspaceRequest {
139 name: workspace.clone(),
140 description: None,
141 visibility: self.visibility,
142 };
143
144 match client.create_workspace(&ws_req).await {
145 Ok(ws) => {
146 print_success(&format!("Created workspace: {}", ws.slug));
147 }
148 Err(e) => {
149 // 409 means already exists — that's fine.
150 let msg = e.to_string();
151 if msg.contains("409")
152 || msg.contains("conflict")
153 || msg.contains("Conflict")
154 {
155 print_info(&format!(
156 "Workspace '{}' already exists, using it.",
157 workspace
158 ));
159 } else {
160 return Err(remote_err(e));
161 }
162 }
163 }
164 }
165 }
166
167 // 4. Create the project on the server.
168 let proj_req = CreateProjectRequest {
169 name: self.name.clone(),
170 description: self.description.clone(),
171 default_view: "dev".to_string(),
172 kind: self.kind.clone(),
173 visibility: self.visibility,

Callers 1

runMethod · 0.45

Calls 15

find_repository_rootFunction · 0.85
openFunction · 0.85
RepositoryClass · 0.85
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

Tested by

no test coverage detected