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

Method run

atomic-cli/src/commands/project/list.rs:71–132  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

build_client_with_orgFunction · 0.85
resolve_workspaceFunction · 0.85
print_hintFunction · 0.85
list_projectsMethod · 0.80
set_columnsMethod · 0.80
add_rowMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected