diff --git a/brood/src/commands.rs b/brood/src/commands.rs new file mode 100644 index 0000000..76837ed --- /dev/null +++ b/brood/src/commands.rs @@ -0,0 +1,5 @@ +mod ingest; +mod reexport; + +pub use ingest::ingest; +pub use reexport::reexport; diff --git a/brood/src/commands/reexport.rs b/brood/src/commands/reexport.rs new file mode 100644 index 0000000..9e45f3c --- /dev/null +++ b/brood/src/commands/reexport.rs @@ -0,0 +1,17 @@ +use std::fs::File; +use std::io::{self, BufReader, BufWriter}; +use std::path::Path; + +use crate::data::AdjacencyList; + +pub fn reexport(from: &Path, to: &Path) -> io::Result<()> { + eprintln!(">> Import"); + let from = BufReader::new(File::open(from)?); + let data = AdjacencyList::read(from)?; + + eprintln!(">> Export"); + let to = BufWriter::new(File::create(to)?); + data.write(to)?; + + Ok(()) +} diff --git a/brood/src/main.rs b/brood/src/main.rs index 65020ae..609b45e 100644 --- a/brood/src/main.rs +++ b/brood/src/main.rs @@ -11,6 +11,8 @@ use clap::Parser; enum Command { /// Read sift data on stdin and output brood data. Ingest, + /// Read and reexport brood data. + Reexport { to: PathBuf }, } #[derive(Debug, Parser)] @@ -24,5 +26,6 @@ fn main() -> io::Result<()> { let args = Args::parse(); match args.command { Command::Ingest => commands::ingest(&args.datafile), + Command::Reexport { to } => commands::reexport(&args.datafile, &to), } }