kaizen/shell/
core_query.rs1use crate::core_loop::time;
3use crate::shell::cli::workspace_path;
4use crate::store::Store;
5use anyhow::Result;
6use std::path::Path;
7
8pub fn cmd_query(
9 workspace: Option<&Path>,
10 expr: &str,
11 since: Option<&str>,
12 limit: usize,
13 json: bool,
14) -> Result<()> {
15 let ws = workspace_path(workspace)?;
16 let store = Store::open(&crate::core::workspace::db_path(&ws)?)?;
17 let start = time::parse_window(since, 7)?;
18 let hits = crate::core_loop::query::run(&store, &ws.to_string_lossy(), expr, start, limit)?;
19 if json {
20 println!("{}", serde_json::to_string_pretty(&hits)?);
21 } else {
22 print_hits(&hits);
23 }
24 Ok(())
25}
26
27pub fn print_hits(hits: &[crate::core_loop::TraceHit]) {
28 println!("{:<40} {:>6} {:<12} SUMMARY", "SESSION", "SEQ", "KIND");
29 for h in hits {
30 let seq = h.seq.map(|s| s.to_string()).unwrap_or_else(|| "-".into());
31 println!(
32 "{:<40} {:>6} {:<12} {}",
33 h.session_id, seq, h.kind, h.summary
34 );
35 }
36}