add CLI option to identify a command with a custom name

CLI option `--name` can be used to define the name to identify a
command. If not passed, then the command itself is used. Commands
and names are paired in the same order: The first command executed gets
the first name passed as option.

Close #326
This commit is contained in:
Stéphane Campinas authored and David Peter committed 2020-10-15 22:42:44 +02:00
1 parent 674b5422ab
commit 0f0a109ca0
4 files changed
+27 -2

No files matched your search

+10
View File
@@ -226,6 +226,16 @@ fn build_app() -> App<'static, 'static> {
when trying to benchmark output speed.",
),
)
.arg(
Arg::with_name("command-name")
.long("name")
.short("n")
.takes_value(true)
.multiple(true)
.number_of_values(1)
.value_name("NAME")
.help("Give a meaningful name to a command"),
)
.help_message("Print this help message.")
.version_message("Show version information.")
}
+10 -2
View File
@@ -202,12 +202,20 @@ pub fn run_benchmark(
shell_spawning_time: TimingResult,
options: &HyperfineOptions,
) -> io::Result<BenchmarkResult> {
let shell_cmd = cmd.get_shell_command();
let command_name = if let Some(names) = &options.names {
names.get(num).unwrap_or(&shell_cmd)
} else {
&shell_cmd
};
let command_name = command_name.to_string();
if options.output_style != OutputStyleOption::Disabled {
println!(
"{}{}: {}",
"Benchmark #".bold(),
(num + 1).to_string().bold(),
cmd
&command_name
);
}
@@ -415,7 +423,7 @@ pub fn run_benchmark(
run_cleanup_command(&options.shell, &cleanup_cmd, options.show_output)?;
Ok(BenchmarkResult::new(
cmd.get_shell_command(),
command_name,
t_mean,
t_stddev,
t_median,
+3
View File
@@ -210,11 +210,14 @@ pub struct HyperfineOptions {
/// Which time unit to use for CLI & Markdown output
pub time_unit: Option<Unit>,
pub names: Option<Vec<String>>,
}
impl Default for HyperfineOptions {
fn default() -> HyperfineOptions {
HyperfineOptions {
names: None,
warmup_count: 0,
runs: Runs::default(),
min_time_sec: 3.0,
+4
View File
@@ -127,6 +127,10 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions,
(None, None) => {}
};
options.names = matches
.values_of("command-name")
.map(|values| values.map(String::from).collect::<Vec<String>>());
options.preparation_command = matches
.values_of("prepare")
.map(|values| values.map(String::from).collect::<Vec<String>>());