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
Provenance
- Commit
33f8d03- Tree
b3142e2- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
b54b2f8
2 files changed+22 added−21 removed
modified:src/export/mod.rs+20 added
13 unmodified lines14 use crate::benchmark_result::BenchmarkResult;15 use crate::units::Unit;16 17 use anyhow::{Context, Result};18+use clap::ArgMatches;19 20 /// The desired form of exporter to use for a given file.21 #[derive(Clone)]22 pub enum ExportType {27 unmodified lines50 exporters: Vec<ExporterWithFilename>,51 }52 53 impl 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+ }72+73 /// 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 linesmodified:src/main.rs+2 added-21 removed
27 unmodified lines28 use benchmark::{mean_shell_spawning_time, run_benchmark};29 use benchmark_result::BenchmarkResult;30 use command::Command;31 use error::OptionsError;32-use export::{ExportManager, ExportType};32+use export::ExportManager;33 use options::{Options, OutputStyleOption};34 use parameter_range::get_parameterized_commands;35 use tokenize::tokenize;36 use types::ParameterValue;80 unmodified lines117 118 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)?;122 123 run_benchmarks_and_print_comparison(&commands, &options, &export_manager)124 }125 6 unmodified lines132 }133 }134 }135 136-/// Build the ExportManager that will export the results specified137-/// in the given ArgMatches138-fn 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-}154-136 /// Build the commands to benchmark137 fn 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