mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 00:38:56 +00:00
Move build_export_manager to ExportManager
This commit is contained in:
1 parent
b54b2f81f4
commit
33f8d03d6b
2 files changed
+22
-21
No files matched your search
@@ -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)
|
||||
|
||||
+2
-21
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user