From 8f15eb79af7cba799a0f1286f277bd49353b5ca3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 16 Jan 2022 11:21:34 +0200 Subject: feat: allow report to write to named file Sponsored-by: author --- src/bin/obnam-benchmark.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs index 8b75229..db04d0a 100644 --- a/src/bin/obnam-benchmark.rs +++ b/src/bin/obnam-benchmark.rs @@ -182,6 +182,10 @@ impl Steps { #[derive(Debug, StructOpt)] struct Report { + /// File where to write the report. Stdout by default. + #[structopt(short, long, parse(from_os_str))] + output: Option, + /// Names of the results file for which to produce a report. #[structopt(parse(from_os_str))] filenames: Vec, @@ -190,11 +194,16 @@ struct Report { impl Report { fn run(&self) -> anyhow::Result<()> { info!("Reporting results"); - let mut report = Reporter::default(); + let mut reporter = Reporter::default(); for filename in self.filenames.iter() { - report.push(SuiteMeasurements::from_file(filename)?); + reporter.push(SuiteMeasurements::from_file(filename)?); + } + if let Some(output) = &self.output { + let mut file = File::create(output)?; + reporter.write(&mut file)?; + } else { + reporter.write(&mut std::io::stdout())?; } - report.write(&mut std::io::stdout())?; Ok(()) } } -- cgit v1.2.1