MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / handle_projects_action

Function handle_projects_action

src/project_cmd.rs:11–54  ·  view source on GitHub ↗
(action: ProjectsAction)

Source from the content-addressed store, hash-verified

9const MAX_LIMIT: usize = 1_000;
10
11pub(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
56fn bounded_limit(limit: usize) -> usize {
57 limit.clamp(1, MAX_LIMIT)

Callers 1

dispatch_commandFunction · 0.85

Calls 7

print_projectsFunction · 0.85
print_project_tableFunction · 0.85
project_contextFunction · 0.85
print_project_contextFunction · 0.85
list_code_projectsMethod · 0.80
search_code_projectsMethod · 0.80
bounded_limitFunction · 0.70

Tested by

no test coverage detected