Add reexport command

This commit is contained in:
Joscha 2022-10-03 18:07:30 +02:00
parent 266f001d46
commit e74eee89e6
3 changed files with 25 additions and 0 deletions

5
brood/src/commands.rs Normal file
View file

@ -0,0 +1,5 @@
mod ingest;
mod reexport;
pub use ingest::ingest;
pub use reexport::reexport;

View file

@ -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(())
}

View file

@ -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),
}
}