summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Peter <mail@david-peter.de>2022-02-06 18:22:55 +0100
committerDavid Peter <sharkdp@users.noreply.github.com>2022-02-06 20:19:50 +0100
commit33f8d03d6beb7ad0cc83443f8652e2e9eb501a6d (patch)
treeb3142e21a3395563311831ad9f3094060738f0aa
parentb54b2f81f414a73b5422bd443b7096f935e05e61 (diff)
Move build_export_manager to ExportManager
-rw-r--r--src/export/mod.rs20
-rw-r--r--src/main.rs23
2 files changed, 22 insertions, 21 deletions
diff --git a/src/export/mod.rs b/src/export/mod.rs
index 1c72c7d..9b6beee 100644
--- a/src/export/mod.rs
+++ b/src/export/mod.rs
@@ -15,6 +15,7 @@ use crate::benchmark_result::BenchmarkResult;
use crate::units::Unit;
use anyhow::{Context, Result};
+use clap::ArgMatches;
/// The desired form of exporter to use for a given file.
#[derive(Clone)]
@@ -50,6 +51,25 @@ pub struct ExportManager {
}
impl ExportManager {
+ /// Build the ExportManager that will export the results specified
+ /// in the given ArgMatches
+ pub fn from_cli_arguments(matches: &ArgMatches) -> Result<Self> {
+ let mut export_manager = Self::default();
+ {
+ let mut add_exporter = |flag, exporttype| -> Result<()> {
+ if let Some(filename) = matches.value_of(flag) {
+ export_manager.add_exporter(exporttype, filename)?;
+ }
+ Ok(())
+ };
+ add_exporter("export-asciidoc", ExportType::Asciidoc)?;
+ add_exporter("export-json", ExportType::Json)?;
+ add_exporter("export-csv", ExportType::Csv)?;
+ add_exporter("export-markdown", ExportType::Markdown)?;
+ }
+ Ok(export_manager)
+ }
+
/// Add an additional exporter to the ExportManager
pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) -> Result<()> {
let _ = File::create(filename)
diff --git a/src/main.rs b/src/main.rs
index a3755d8..819f0e3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,7 +29,7 @@ use benchmark::{mean_shell_spawning_time, run_benchmark};
use benchmark_result::BenchmarkResult;
use command::Command;
use error::OptionsError;
-use export::{ExportManager, ExportType};
+use export::ExportManager;
use options::{Options, OutputStyleOption};
use parameter_range::get_parameterized_commands;
use tokenize::tokenize;
@@ -118,7 +118,7 @@ fn run() -> Result<()> {
let matches = get_arg_matches(env::args_os());
let options = Options::from_cli_arguments(&matches)?;
let commands = build_commands(&matches)?;
- let export_manager = build_export_manager(&matches)?;
+ let export_manager = ExportManager::from_cli_arguments(&matches)?;
run_benchmarks_and_print_comparison(&commands, &options, &export_manager)
}
@@ -133,25 +133,6 @@ fn main() {
}
}
-/// Build the ExportManager that will export the results specified
-/// in the given ArgMatches
-fn build_export_manager(matches: &ArgMatches) -> Result<ExportManager> {
- let mut export_manager = ExportManager::default();
- {
- let mut add_exporter = |flag, exporttype| -> Result<()> {
- if let Some(filename) = matches.value_of(flag) {
- export_manager.add_exporter(exporttype, filename)?;
- }
- Ok(())
- };
- add_exporter("export-asciidoc", ExportType::Asciidoc)?;
- add_exporter("export-json", ExportType::Json)?;
- add_exporter("export-csv", ExportType::Csv)?;
- add_exporter("export-markdown", ExportType::Markdown)?;
- }
- Ok(export_manager)
-}
-
/// Build the commands to benchmark
fn build_commands(matches: &ArgMatches) -> Result<Vec<Command>> {
let command_names = matches.values_of("command-name");