(&self)
| 69 | |
| 70 | impl Command for ProjectList { |
| 71 | fn run(&self) -> CliResult<()> { |
| 72 | let rt = tokio::runtime::Runtime::new().map_err(|e| { |
| 73 | CliError::Internal(anyhow::anyhow!("Failed to create async runtime: {}", e)) |
| 74 | })?; |
| 75 | |
| 76 | rt.block_on(async { |
| 77 | let (client, org_slug) = |
| 78 | build_client_with_org(self.org.as_deref(), self.server.as_deref()).await?; |
| 79 | let workspace = resolve_workspace(&org_slug, self.workspace.as_deref())?; |
| 80 | |
| 81 | let projects = client.list_projects(&workspace).await.map_err(remote_err)?; |
| 82 | |
| 83 | if self.format == "json" { |
| 84 | println!( |
| 85 | "{}", |
| 86 | serde_json::to_string_pretty(&projects).unwrap_or_default() |
| 87 | ); |
| 88 | return Ok(()); |
| 89 | } |
| 90 | |
| 91 | if projects.is_empty() { |
| 92 | // Mirror the flags the user typed so the suggested follow-up |
| 93 | // resolves to the same org/workspace they were just looking |
| 94 | // at — not whatever the current defaults are. |
| 95 | let mut create_hint = String::from("atomic project create <name>"); |
| 96 | if let Some(ws) = self.workspace.as_deref() { |
| 97 | create_hint.push_str(&format!(" --workspace {ws}")); |
| 98 | } |
| 99 | if let Some(org) = self.org.as_deref() { |
| 100 | create_hint.push_str(&format!(" --org {org}")); |
| 101 | } |
| 102 | print_hint(&format!( |
| 103 | "No projects found in workspace '{workspace}'. \ |
| 104 | Create one with '{create_hint}'." |
| 105 | )); |
| 106 | return Ok(()); |
| 107 | } |
| 108 | |
| 109 | let mut table = Table::new(); |
| 110 | table.set_columns(vec![ |
| 111 | Column::new("NAME"), |
| 112 | Column::new("SLUG"), |
| 113 | Column::new("VIEW"), |
| 114 | Column::new("VISIBILITY"), |
| 115 | Column::new("CREATED"), |
| 116 | ]); |
| 117 | |
| 118 | for proj in &projects { |
| 119 | table.add_row(vec![ |
| 120 | proj.name.clone(), |
| 121 | proj.slug.clone(), |
| 122 | proj.default_view.clone(), |
| 123 | proj.visibility.to_string(), |
| 124 | format_timestamp(&proj.created_at), |
| 125 | ]); |
| 126 | } |
| 127 | |
| 128 | println!("{}", table); |
nothing calls this directly
no test coverage detected