(action: ProjectsAction)
| 9 | const MAX_LIMIT: usize = 1_000; |
| 10 | |
| 11 | pub(crate) async fn handle_projects_action(action: ProjectsAction) -> Result<()> { |
| 12 | let db = GlobalDb::open() |
| 13 | .await |
| 14 | .ok_or_else(|| TraceDecayError::Config { |
| 15 | message: |
| 16 | "no TraceDecay global registry found; run `tracedecay init` in a project first" |
| 17 | .to_string(), |
| 18 | })?; |
| 19 | |
| 20 | match action { |
| 21 | ProjectsAction::List { limit, json } => { |
| 22 | let limit = bounded_limit(limit); |
| 23 | let projects = db.list_code_projects(limit).await; |
| 24 | print_projects("registered projects", projects, limit, json)?; |
| 25 | } |
| 26 | ProjectsAction::Search { query, limit, json } => { |
| 27 | let limit = bounded_limit(limit); |
| 28 | let projects = db.search_code_projects(&query, limit).await; |
| 29 | if json { |
| 30 | println!( |
| 31 | "{}", |
| 32 | serde_json::to_string_pretty(&json!({ |
| 33 | "query": query, |
| 34 | "limit": limit, |
| 35 | "projects": projects, |
| 36 | }))? |
| 37 | ); |
| 38 | } else { |
| 39 | print_project_table(&format!("projects matching \"{query}\""), &projects); |
| 40 | } |
| 41 | } |
| 42 | ProjectsAction::Context { selector, json } => { |
| 43 | let context = project_context(&db, &selector).await.ok_or_else(|| { |
| 44 | TraceDecayError::Config { |
| 45 | message: format!( |
| 46 | "registered project not found for '{selector}'; try `tracedecay projects search {selector}`" |
| 47 | ), |
| 48 | } |
| 49 | })?; |
| 50 | print_project_context(&context, json)?; |
| 51 | } |
| 52 | } |
| 53 | Ok(()) |
| 54 | } |
| 55 | |
| 56 | fn bounded_limit(limit: usize) -> usize { |
| 57 | limit.clamp(1, MAX_LIMIT) |
no test coverage detected