Skip to content
Myr

add CLI option to identify a command with a custom name

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Stéphane Campinas · committed by David Peter · parent 674b542 · Browse files · 4 files+27 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+27 added−2 removed

  • other:+27 added−2 removed

4 files+27 added−2 removed

modified:src/hyperfine/app.rs+10 added
224 unmodified lines
225 so it should only be used for debugging purposes or \226 when trying to benchmark output speed.",227 ),228 )229 .arg(230 Arg::with_name("command-name")231 .long("name")232 .short("n")233 .takes_value(true)234 .multiple(true)235 .number_of_values(1)236 .value_name("NAME")237 .help("Give a meaningful name to a command"),238 )239 .help_message("Print this help message.")240 .version_message("Show version information.")241}
modified:src/hyperfine/benchmark.rs+10 added-2 removed
200 unmodified lines
201 cmd: &Command<'_>,202 shell_spawning_time: TimingResult,203 options: &HyperfineOptions,204) -> io::Result<BenchmarkResult> {205 let shell_cmd = cmd.get_shell_command();206 let command_name = if let Some(names) = &options.names {207 names.get(num).unwrap_or(&shell_cmd)208 } else {209 &shell_cmd210 };211 let command_name = command_name.to_string();212213 if options.output_style != OutputStyleOption::Disabled {214 println!(215 "{}{}: {}",216 "Benchmark #".bold(),217 (num + 1).to_string().bold(),210 cmd218 &command_name219 );220 }221222 let mut times_real: Vec<Second> = vec![];
199 unmodified lines
422 });423 run_cleanup_command(&options.shell, &cleanup_cmd, options.show_output)?;424425 Ok(BenchmarkResult::new(418 cmd.get_shell_command(),426 command_name,427 t_mean,428 t_stddev,429 t_median,430 user_mean,
10 unmodified lines
modified:src/hyperfine/types.rs+3 added
208 unmodified lines
209 pub show_output: bool,210211 /// Which time unit to use for CLI & Markdown output212 pub time_unit: Option<Unit>,213214 pub names: Option<Vec<String>>,215}216217impl Default for HyperfineOptions {218 fn default() -> HyperfineOptions {219 HyperfineOptions {220 names: None,221 warmup_count: 0,222 runs: Runs::default(),223 min_time_sec: 3.0,224 failure_action: CmdFailureAction::RaiseError,
76 unmodified lines
modified:src/main.rs+4 added
125 unmodified lines
126 }127 (None, None) => {}128 };129130 options.names = matches131 .values_of("command-name")132 .map(|values| values.map(String::from).collect::<Vec<String>>());133134 options.preparation_command = matches135 .values_of("prepare")136 .map(|values| values.map(String::from).collect::<Vec<String>>());137
188 unmodified lines