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