carp_cli/commands/
list.rs1use crate::api::ApiClient;
2use crate::config::ConfigManager;
3use crate::utils::error::CarpResult;
4use colored::*;
5
6pub async fn execute(verbose: bool) -> CarpResult<()> {
8 if verbose {
9 println!("Fetching all available agents...");
10 }
11
12 let config = ConfigManager::load_with_env_checks()?;
13 let client = ApiClient::new(&config)?;
14
15 let response = client.search("", Some(1000), false).await?;
17
18 if response.agents.is_empty() {
19 println!("{}", "No agents found in the registry.".yellow());
20 return Ok(());
21 }
22
23 println!(
24 "{} {} agents available:\n",
25 "Found".green().bold(),
26 response.total
27 );
28
29 for agent in &response.agents {
30 println!("{} {}", agent.name.bold().blue(), agent.version.dimmed());
31 println!(" {}", agent.description);
32 println!(
33 " by {} • {} views",
34 agent.author.green(),
35 agent.download_count.to_string().cyan()
36 );
37
38 if !agent.tags.is_empty() {
39 print!(" tags: ");
40 for (i, tag) in agent.tags.iter().enumerate() {
41 if i > 0 {
42 print!(", ");
43 }
44 print!("{}", tag.yellow());
45 }
46 println!();
47 }
48
49 if verbose {
50 println!(" created: {}", agent.created_at.format("%Y-%m-%d"));
51 if let Some(homepage) = &agent.homepage {
52 println!(" homepage: {}", homepage.blue().underline());
53 }
54 if let Some(repository) = &agent.repository {
55 println!(" repository: {}", repository.blue().underline());
56 }
57 }
58
59 println!();
60 }
61
62 if response.total > response.agents.len() {
63 println!(
64 "{} Showing {} of {} agents. Some agents may be hidden due to API limits.",
65 "Note:".yellow().bold(),
66 response.agents.len(),
67 response.total
68 );
69 }
70
71 Ok(())
72}