| 120 | |
| 121 | impl Command for ProjectCreate { |
| 122 | fn run(&self) -> CliResult<()> { |
| 123 | if self.name.is_empty() { |
| 124 | return Err(CliError::InvalidArgument { |
| 125 | message: "Project name is required.".to_string(), |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | let rt = tokio::runtime::Runtime::new().map_err(|e| { |
| 130 | CliError::Internal(anyhow::anyhow!("Failed to create async runtime: {}", e)) |
| 131 | })?; |
| 132 | |
| 133 | rt.block_on(async { |
| 134 | let (client, org_slug) = |
| 135 | build_client_with_org(self.org.as_deref(), self.server.as_deref()).await?; |
| 136 | let workspace = resolve_workspace(&org_slug, self.workspace.as_deref())?; |
| 137 | let visibility = self.parse_visibility()?; |
| 138 | |
| 139 | let req = CreateProjectRequest { |
| 140 | name: self.name.clone(), |
| 141 | description: self.description.clone(), |
| 142 | default_view: self.default_view.clone(), |
| 143 | kind: self.kind.clone(), |
| 144 | visibility, |
| 145 | }; |
| 146 | |
| 147 | let project = client |
| 148 | .create_project(&workspace, &req) |
| 149 | .await |
| 150 | .map_err(remote_err)?; |
| 151 | |
| 152 | print_success(&format!( |
| 153 | "Created project: {} (slug: {})", |
| 154 | project.name, project.slug |
| 155 | )); |
| 156 | println!(); |
| 157 | |
| 158 | let vcs_url = format!( |
| 159 | "{}/workspaces/{}/projects/{}/code", |
| 160 | client.base_url(), |
| 161 | workspace, |
| 162 | project.slug, |
| 163 | ); |
| 164 | |
| 165 | let details = KeyValueTable::new() |
| 166 | .add("Workspace", &workspace) |
| 167 | .add("Default view", &project.default_view) |
| 168 | .add("Visibility", project.visibility.to_string()) |
| 169 | .add("VCS URL", &vcs_url); |
| 170 | |
| 171 | println!("{}", details); |
| 172 | |
| 173 | // Mirror what the user typed when building the follow-up hint. |
| 174 | // Omitting flags that fell back to defaults reinforces that the |
| 175 | // default-workspace / default-org config is in effect. |
| 176 | let mut init_cmd = format!("atomic project init {}", project.slug); |
| 177 | if self.workspace.is_some() { |
| 178 | init_cmd.push_str(&format!(" --workspace {workspace}")); |
| 179 | } |