"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/options.rs" between
hyperfine-1.14.0.tar.gz and hyperfine-1.15.0.tar.gz

About: hyperfine is a command-line benchmarking tool.

options.rs  (hyperfine-1.14.0):options.rs  (hyperfine-1.15.0)
use std::fs::File; use std::fs::File;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::{cmp, fmt, io}; use std::{cmp, env, fmt, io};
use anyhow::ensure; use anyhow::ensure;
use atty::Stream; use atty::Stream;
use clap::ArgMatches; use clap::ArgMatches;
use crate::command::Commands; use crate::command::Commands;
use crate::error::OptionsError; use crate::error::OptionsError;
use crate::util::units::{Second, Unit}; use crate::util::units::{Second, Unit};
use anyhow::Result; use anyhow::Result;
skipping to change at line 70 skipping to change at line 70
Shell::Custom(cmdline) => { Shell::Custom(cmdline) => {
let mut c = Command::new(&cmdline[0]); let mut c = Command::new(&cmdline[0]);
c.args(&cmdline[1..]); c.args(&cmdline[1..]);
c c
} }
} }
} }
} }
/// Action to take when an executed command fails. /// Action to take when an executed command fails.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmdFailureAction { pub enum CmdFailureAction {
/// Exit with an error message /// Exit with an error message
RaiseError, RaiseError,
/// Simply ignore the non-zero exit code /// Simply ignore the non-zero exit code
Ignore, Ignore,
} }
/// Output style type option /// Output style type option
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OutputStyleOption { pub enum OutputStyleOption {
/// Do not output with colors or any special formatting /// Do not output with colors or any special formatting
Basic, Basic,
/// Output with full color and formatting /// Output with full color and formatting
Full, Full,
/// Keep elements such as progress bar, but use no coloring /// Keep elements such as progress bar, but use no coloring
NoColor, NoColor,
skipping to change at line 114 skipping to change at line 114
pub max: Option<u64>, pub max: Option<u64>,
} }
impl Default for RunBounds { impl Default for RunBounds {
fn default() -> Self { fn default() -> Self {
RunBounds { min: 10, max: None } RunBounds { min: 10, max: None }
} }
} }
/// How to handle the output of benchmarked commands /// How to handle the output of benchmarked commands
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandOutputPolicy { pub enum CommandOutputPolicy {
/// Redirect output to the null device /// Redirect output to the null device
Null, Null,
/// Feed output through a pipe before discarding it /// Feed output through a pipe before discarding it
Pipe, Pipe,
/// Redirect output to a file /// Redirect output to a file
File(PathBuf), File(PathBuf),
skipping to change at line 229 skipping to change at line 229
} }
impl Options { impl Options {
pub fn from_cli_arguments<'a>(matches: &ArgMatches) -> Result<Self, OptionsE rror<'a>> { pub fn from_cli_arguments<'a>(matches: &ArgMatches) -> Result<Self, OptionsE rror<'a>> {
let mut options = Self::default(); let mut options = Self::default();
let param_to_u64 = |param| { let param_to_u64 = |param| {
matches matches
.value_of(param) .value_of(param)
.map(|n| { .map(|n| {
n.parse::<u64>() n.parse::<u64>()
.map_err(|e| OptionsError::NumericParsingError(param, e) ) .map_err(|e| OptionsError::IntParsingError(param, e))
}) })
.transpose() .transpose()
}; };
options.warmup_count = param_to_u64("warmup")?.unwrap_or(options.warmup_ count); options.warmup_count = param_to_u64("warmup")?.unwrap_or(options.warmup_ count);
let mut min_runs = param_to_u64("min-runs")?; let mut min_runs = param_to_u64("min-runs")?;
let mut max_runs = param_to_u64("max-runs")?; let mut max_runs = param_to_u64("max-runs")?;
if let Some(runs) = param_to_u64("runs")? { if let Some(runs) = param_to_u64("runs")? {
skipping to change at line 301 skipping to change at line 301
Some("full") => OutputStyleOption::Full, Some("full") => OutputStyleOption::Full,
Some("basic") => OutputStyleOption::Basic, Some("basic") => OutputStyleOption::Basic,
Some("nocolor") => OutputStyleOption::NoColor, Some("nocolor") => OutputStyleOption::NoColor,
Some("color") => OutputStyleOption::Color, Some("color") => OutputStyleOption::Color,
Some("none") => OutputStyleOption::Disabled, Some("none") => OutputStyleOption::Disabled,
_ => { _ => {
if options.command_output_policy == CommandOutputPolicy::Inherit if options.command_output_policy == CommandOutputPolicy::Inherit
|| !atty::is(Stream::Stdout) || !atty::is(Stream::Stdout)
{ {
OutputStyleOption::Basic OutputStyleOption::Basic
} else if env::var_os("TERM")
.map(|t| t == "unknown" || t == "dumb")
.unwrap_or(true)
|| env::var_os("NO_COLOR")
.map(|t| !t.is_empty())
.unwrap_or(false)
{
OutputStyleOption::NoColor
} else { } else {
OutputStyleOption::Full OutputStyleOption::Full
} }
} }
}; };
match options.output_style { match options.output_style {
OutputStyleOption::Basic | OutputStyleOption::NoColor => { OutputStyleOption::Basic | OutputStyleOption::NoColor => {
colored::control::set_override(false) colored::control::set_override(false)
} }
skipping to change at line 340 skipping to change at line 348
if matches.is_present("ignore-failure") { if matches.is_present("ignore-failure") {
options.command_failure_action = CmdFailureAction::Ignore; options.command_failure_action = CmdFailureAction::Ignore;
} }
options.time_unit = match matches.value_of("time-unit") { options.time_unit = match matches.value_of("time-unit") {
Some("millisecond") => Some(Unit::MilliSecond), Some("millisecond") => Some(Unit::MilliSecond),
Some("second") => Some(Unit::Second), Some("second") => Some(Unit::Second),
_ => None, _ => None,
}; };
if let Some(time) = matches.value_of("min-benchmarking-time") {
options.min_benchmarking_time = time
.parse::<f64>()
.map_err(|e| OptionsError::FloatParsingError("min-benchmarking-t
ime", e))?;
}
Ok(options) Ok(options)
} }
pub fn validate_against_command_list(&self, commands: &Commands) -> Result<( )> { pub fn validate_against_command_list(&self, commands: &Commands) -> Result<( )> {
if let Some(preparation_command) = &self.preparation_command { if let Some(preparation_command) = &self.preparation_command {
ensure!( ensure!(
preparation_command.len() <= 1 preparation_command.len() <= 1
|| commands.num_commands() == preparation_command.len(), || commands.num_commands() == preparation_command.len(),
"The '--prepare' option has to be provided just once or N times, where N is the \ "The '--prepare' option has to be provided just once or N times, where N is the \
number of benchmark commands." number of benchmark commands."
 End of changes. 7 change blocks. 
5 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)