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