Address review comments

This commit is contained in:
Tavian Barnes authored and David Peter committed 2022-05-17 22:30:45 +02:00
1 parent efdf735723
commit 3df63ba2bb
3 files changed
+28 -31

No files matched your search

+15 -15
View File
@@ -113,8 +113,8 @@ impl Default for RunBounds {
/// How to handle the output of benchmarked commands
#[derive(Debug, Clone, PartialEq)]
pub enum CommandOutputPolicy {
/// Discard all output
Discard,
/// Redirect output to the null device
Null,
/// Feed output through a pipe before discarding it
Pipe,
@@ -123,19 +123,19 @@ pub enum CommandOutputPolicy {
File(PathBuf),
/// Show command output on the terminal
Forward,
Inherit,
}
impl Default for CommandOutputPolicy {
fn default() -> Self {
CommandOutputPolicy::Discard
CommandOutputPolicy::Null
}
}
impl CommandOutputPolicy {
pub fn get_stdout_stderr(&self) -> io::Result<(Stdio, Stdio)> {
let streams = match self {
CommandOutputPolicy::Discard => (Stdio::null(), Stdio::null()),
CommandOutputPolicy::Null => (Stdio::null(), Stdio::null()),
// Typically only stdout is performance-relevant, so just pipe that
CommandOutputPolicy::Pipe => (Stdio::piped(), Stdio::null()),
@@ -145,7 +145,7 @@ impl CommandOutputPolicy {
(file.into(), Stdio::null())
}
CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()),
CommandOutputPolicy::Inherit => (Stdio::inherit(), Stdio::inherit()),
};
Ok(streams)
@@ -212,7 +212,7 @@ impl Default for Options {
cleanup_command: None,
output_style: OutputStyleOption::Full,
executor_kind: ExecutorKind::default(),
command_output_policy: CommandOutputPolicy::Discard,
command_output_policy: CommandOutputPolicy::Null,
time_unit: None,
}
}
@@ -269,12 +269,12 @@ impl Options {
options.cleanup_command = matches.value_of("cleanup").map(String::from);
options.command_output_policy = if matches.is_present("show-output") {
CommandOutputPolicy::Forward
CommandOutputPolicy::Inherit
} else if let Some(output) = matches.value_of("output") {
match output {
"null" => CommandOutputPolicy::Discard,
"null" => CommandOutputPolicy::Null,
"pipe" => CommandOutputPolicy::Pipe,
"inherit" => CommandOutputPolicy::Forward,
"inherit" => CommandOutputPolicy::Inherit,
arg => {
let path = PathBuf::from(arg);
if path.components().count() <= 1 {
@@ -284,7 +284,7 @@ impl Options {
}
}
} else {
CommandOutputPolicy::Discard
CommandOutputPolicy::Null
};
options.output_style = match matches.value_of("style") {
@@ -294,12 +294,12 @@ impl Options {
Some("color") => OutputStyleOption::Color,
Some("none") => OutputStyleOption::Disabled,
_ => {
if options.command_output_policy != CommandOutputPolicy::Forward
&& atty::is(Stream::Stdout)
if options.command_output_policy == CommandOutputPolicy::Inherit
|| !atty::is(Stream::Stdout)
{
OutputStyleOption::Full
} else {
OutputStyleOption::Basic
} else {
OutputStyleOption::Full
}
}
};