context_harness/
export.rs1use anyhow::Result;
8use std::path::Path;
9
10use crate::app_store::{AppStore, SqliteAppStore};
11use crate::config::Config;
12
13pub async fn run_export(config: &Config, output: Option<&Path>) -> Result<()> {
18 let store = SqliteAppStore::connect(config).await?;
19 let data = store.export_index().await?;
20 let doc_count = data.documents.len();
21 let chunk_count = data.chunks.len();
22 let json = serde_json::to_string_pretty(&data)?;
23
24 match output {
25 Some(path) => {
26 if let Some(parent) = path.parent() {
27 std::fs::create_dir_all(parent)?;
28 }
29 std::fs::write(path, &json)?;
30 eprintln!(
31 "Exported {} documents, {} chunks to {}",
32 doc_count,
33 chunk_count,
34 path.display()
35 );
36 }
37 None => {
38 println!("{}", json);
39 }
40 }
41
42 store.close().await;
43 Ok(())
44}