(&self)
| 73 | |
| 74 | impl TeamList { |
| 75 | async fn execute(&self) -> CliResult<()> { |
| 76 | let client = build_client(self.org.as_deref(), None).await?; |
| 77 | let slug = client.org_slug().to_string(); |
| 78 | |
| 79 | let teams = atomic_teams::team::list_teams(&client, &slug) |
| 80 | .await |
| 81 | .map_err(|e| CliError::RemoteError { |
| 82 | message: e.to_string(), |
| 83 | url: None, |
| 84 | })?; |
| 85 | |
| 86 | let is_json = self |
| 87 | .format |
| 88 | .as_deref() |
| 89 | .map(|f| f.eq_ignore_ascii_case("json")) |
| 90 | .unwrap_or(false); |
| 91 | |
| 92 | if is_json { |
| 93 | let json = serde_json::to_string_pretty(&teams).map_err(|e| { |
| 94 | CliError::Internal(anyhow::anyhow!("Failed to serialize teams: {e}")) |
| 95 | })?; |
| 96 | println!("{json}"); |
| 97 | } else if teams.is_empty() { |
| 98 | print_hint("No teams found in this organization."); |
| 99 | print_hint("Use 'atomic team create <name>' to create one."); |
| 100 | } else { |
| 101 | let mut table = Table::new(); |
| 102 | table.set_columns(vec![ |
| 103 | Column::new("NAME").min_width(20), |
| 104 | Column::new("SLUG").min_width(20), |
| 105 | Column::new("VISIBILITY").min_width(10), |
| 106 | Column::new("CREATED").min_width(20), |
| 107 | ]); |
| 108 | |
| 109 | for team in &teams { |
| 110 | table.add_row(vec![ |
| 111 | team.name.clone(), |
| 112 | team.slug.clone(), |
| 113 | team.visibility.to_string(), |
| 114 | team.created_at.to_rfc3339(), |
| 115 | ]); |
| 116 | } |
| 117 | |
| 118 | println!("{table}"); |
| 119 | |
| 120 | print_hint(&format!("{} team(s) total", teams.len())); |
| 121 | } |
| 122 | |
| 123 | Ok(()) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | #[cfg(test)] |
no test coverage detected