oxibrain_cli/cmd/
ingest.rs1use oxibrain::{Brain, BrainConfig};
2use oxibrain_ports::{ClockPort, SystemClock};
3use std::io::Read;
4use std::path::Path;
5
6pub async fn run(dir: &Path, path: std::path::PathBuf, space: &str) -> anyhow::Result<()> {
7 let content = if path.as_path() == Path::new("-") {
8 let mut s = String::new();
9 std::io::stdin().read_to_string(&mut s)?;
10 s
11 } else {
12 std::fs::read_to_string(&path)?
13 };
14 let brain = Brain::open(BrainConfig::at(dir)).await?;
15 let space_id = brain.ensure_space(space).await?;
16 let id = brain
17 .ingest_note(
18 &space_id,
19 &path.display().to_string(),
20 content,
21 SystemClock.now(),
22 )
23 .await?;
24 println!("ingested episode {id}");
25 Ok(())
26}