diff --git a/src/main.rs b/src/main.rs index 462ddc8..01daa25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{fs::File, io::BufWriter, path::PathBuf}; use clap::{Parser, Subcommand}; @@ -69,8 +69,11 @@ enum Commands { #[arg(short, long, default_value = "0.00000000000000001")] zero_threshold: f64, - #[arg(short, long, value_name = "FILE")] - output: Option, + #[arg(short, long, value_name = "FILE", default_value = "alloc_output.csv")] + output: PathBuf, + + #[arg(short, long)] + msgpack_serialisation: bool, }, CreateProducts { #[arg(short, long, value_name = "FILE")] @@ -129,20 +132,41 @@ fn main() -> anyhow::Result<()> { show_from, zero_threshold, output, - } => coster_rs::reciprocal_allocation( - &mut csv::Reader::from_path(lines)?, - &mut csv::Reader::from_path(accounts)?, - &mut csv::Reader::from_path(allocation_statistics)?, - &mut csv::Reader::from_path(areas)?, - &mut csv::Reader::from_path(cost_centres)?, - &mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("alloc_output.csv")))?, - use_numeric_accounts, - exclude_negative_allocation_statistics, - true, - account_type, - show_from, - zero_threshold, - ), + msgpack_serialisation, + } => { + if msgpack_serialisation { + let mut file = BufWriter::new(File::create(output)?); + coster_rs::reciprocal_allocation( + &mut csv::Reader::from_path(lines)?, + &mut csv::Reader::from_path(accounts)?, + &mut csv::Reader::from_path(allocation_statistics)?, + &mut csv::Reader::from_path(areas)?, + &mut csv::Reader::from_path(cost_centres)?, + &mut rmp_serde::Serializer::new(&mut file), + use_numeric_accounts, + exclude_negative_allocation_statistics, + true, + account_type, + show_from, + zero_threshold, + ) + } else { + coster_rs::reciprocal_allocation( + &mut csv::Reader::from_path(lines)?, + &mut csv::Reader::from_path(accounts)?, + &mut csv::Reader::from_path(allocation_statistics)?, + &mut csv::Reader::from_path(areas)?, + &mut csv::Reader::from_path(cost_centres)?, + &mut csv::Writer::from_path(output)?, + use_numeric_accounts, + exclude_negative_allocation_statistics, + true, + account_type, + show_from, + zero_threshold, + ) + } + } Commands::CreateProducts { definitions, encounters, diff --git a/src/overhead_allocation.rs b/src/overhead_allocation.rs index fa8fa11..e5ba2f5 100644 --- a/src/overhead_allocation.rs +++ b/src/overhead_allocation.rs @@ -780,7 +780,6 @@ impl RecordSerializer for Serializer { #[cfg(test)] mod tests { - use std::fs::File; use crate::reciprocal_allocation; use crate::AccountCost; @@ -789,7 +788,6 @@ mod tests { use crate::TotalDepartmentCost; use super::reciprocal_allocation_impl; - use super::MovedAmount; #[test] fn test_basic() {