Skip to content
Myr

Move build_export_manager to ExportManager

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent b54b2f8 · Browse files · 2 files+22 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+22 added−21 removed

  • other:+22 added−21 removed

2 files+22 added−21 removed

modified:src/export/mod.rs+20 added
13 unmodified lines
14use crate::benchmark_result::BenchmarkResult;15use crate::units::Unit;1617use anyhow::{Context, Result};18use clap::ArgMatches;1920/// The desired form of exporter to use for a given file.21#[derive(Clone)]22pub enum ExportType {
27 unmodified lines
50 exporters: Vec<ExporterWithFilename>,51}5253impl ExportManager {54 /// Build the ExportManager that will export the results specified55 /// in the given ArgMatches56 pub fn from_cli_arguments(matches: &ArgMatches) -> Result<Self> {57 let mut export_manager = Self::default();58 {59 let mut add_exporter = |flag, exporttype| -> Result<()> {60 if let Some(filename) = matches.value_of(flag) {61 export_manager.add_exporter(exporttype, filename)?;62 }63 Ok(())64 };65 add_exporter("export-asciidoc", ExportType::Asciidoc)?;66 add_exporter("export-json", ExportType::Json)?;67 add_exporter("export-csv", ExportType::Csv)?;68 add_exporter("export-markdown", ExportType::Markdown)?;69 }70 Ok(export_manager)71 }7273 /// Add an additional exporter to the ExportManager74 pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) -> Result<()> {75 let _ = File::create(filename)76 .with_context(|| format!("Could not create export file '{}'", filename))?;
31 unmodified lines
modified:src/main.rs+2 added-21 removed
27 unmodified lines
28use benchmark::{mean_shell_spawning_time, run_benchmark};29use benchmark_result::BenchmarkResult;30use command::Command;31use error::OptionsError;32use export::{ExportManager, ExportType};32use export::ExportManager;33use options::{Options, OutputStyleOption};34use parameter_range::get_parameterized_commands;35use tokenize::tokenize;36use types::ParameterValue;
80 unmodified lines
117118 let matches = get_arg_matches(env::args_os());119 let options = Options::from_cli_arguments(&matches)?;120 let commands = build_commands(&matches)?;121 let export_manager = build_export_manager(&matches)?;121 let export_manager = ExportManager::from_cli_arguments(&matches)?;122123 run_benchmarks_and_print_comparison(&commands, &options, &export_manager)124}125
6 unmodified lines
132 }133 }134}135136/// Build the ExportManager that will export the results specified137/// in the given ArgMatches138fn build_export_manager(matches: &ArgMatches) -> Result<ExportManager> {139 let mut export_manager = ExportManager::default();140 {141 let mut add_exporter = |flag, exporttype| -> Result<()> {142 if let Some(filename) = matches.value_of(flag) {143 export_manager.add_exporter(exporttype, filename)?;144 }145 Ok(())146 };147 add_exporter("export-asciidoc", ExportType::Asciidoc)?;148 add_exporter("export-json", ExportType::Json)?;149 add_exporter("export-csv", ExportType::Csv)?;150 add_exporter("export-markdown", ExportType::Markdown)?;151 }152 Ok(export_manager)153}154136/// Build the commands to benchmark137fn build_commands(matches: &ArgMatches) -> Result<Vec<Command>> {138 let command_names = matches.values_of("command-name");139 let command_strings = matches.values_of("command").unwrap();
191 unmodified lines