Skip to content
Myr

Move functions into Scheduler

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

authored by David Peter · committed by David Peter · parent dcfeede · Browse files · 3 files+354 added−359 removed
This commit

State

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

Diff stats

3 files+354 added−359 removed

  • other:+354 added−359 removed

3 files+354 added−359 removed

modified:src/benchmark/scheduler.rs+343 added-353 removed
23 unmodified lines
24use crate::util::units::Second;2526use anyhow::{bail, Result};2728pub struct Scheduler<'a> {29 commands: &'a Commands<'a>,30 options: &'a Options,31 export_manager: &'a ExportManager,32 results: Vec<BenchmarkResult>,33}28///////////////2935impl<'a> Scheduler<'a> {36 pub fn new(37 commands: &'a Commands,38 options: &'a Options,39 export_manager: &'a ExportManager,40 ) -> Self {41 Self {42 commands,43 options,44 export_manager,45 results: vec![],46 }47 }4849 pub fn run_benchmarks(&mut self) -> Result<()> {50 let shell_spawning_time = mean_shell_spawning_time(51 &self.options.shell,52 self.options.output_style,53 self.options.command_output_policy,54 )?;5556 for (num, cmd) in self.commands.iter().enumerate() {57 self.results58 .push(run_benchmark(num, cmd, shell_spawning_time, self.options)?);5960 // We export (all results so far) after each individual benchmark, because61 // we would risk losing all results if a later benchmark fails.62 self.export_manager63 .write_results(&self.results, self.options.time_unit)?;64 }6566 Ok(())67 }6869 pub fn print_relative_speed_comparison(&self) {70 if self.options.output_style == OutputStyleOption::Disabled {71 return;72 }7374 if self.results.len() < 2 {75 return;76 }7778 if let Some(mut annotated_results) = relative_speed::compute(&self.results) {79 annotated_results.sort_by(|l, r| relative_speed::compare_mean_time(l.result, r.result));8081 let fastest = &annotated_results[0];82 let others = &annotated_results[1..];8384 println!("{}", "Summary".bold());85 println!(" '{}' ran", fastest.result.command.cyan());8687 for item in others {88 println!(89 "{}{} times faster than '{}'",90 format!("{:8.2}", item.relative_speed).bold().green(),91 if let Some(stddev) = item.relative_speed_stddev {92 format!(" ± {}", format!("{:.2}", stddev).green())93 } else {94 "".into()95 },96 &item.result.command.magenta()97 );98 }99 } else {100 eprintln!(101 "{}: The benchmark comparison could not be computed as some benchmark times are zero. \102 This could be caused by background interference during the initial calibration phase \103 of hyperfine, in combination with very fast commands (faster than a few milliseconds). \104 Try to re-run the benchmark on a quiet system. If it does not help, you command is \105 most likely too fast to be accurately benchmarked by hyperfine.",106 "Note".bold().red()107 );108 }109 }110}11130/// Correct for shell spawning time31fn subtract_shell_spawning_time(time: Second, shell_spawning_time: Second) -> Second {32 if time < shell_spawning_time {33 0.0
115 unmodified lines
149 time_user: mean(&times_user),150 time_system: mean(&times_system),151 })152}153///////////////154236fn run_intermediate_command(237 shell: &Shell,238 command: &Option<Command<'_>>,239 command_output_policy: CommandOutputPolicy,240 error_output: &'static str,241) -> Result<TimingResult> {242 if let Some(ref cmd) = command {243 let res = time_shell_command(244 shell,245 cmd,246 command_output_policy,247 CmdFailureAction::RaiseError,248 None,249 );250 if res.is_err() {251 bail!(error_output);155pub struct Scheduler<'a> {156 commands: &'a Commands<'a>,157 options: &'a Options,158 export_manager: &'a ExportManager,159 results: Vec<BenchmarkResult>,160}161162impl<'a> Scheduler<'a> {163 pub fn new(164 commands: &'a Commands,165 options: &'a Options,166 export_manager: &'a ExportManager,167 ) -> Self {168 Self {169 commands,170 options,171 export_manager,172 results: vec![],173 }253 return res.map(|r| r.0);174 }255 Ok(TimingResult {256 ..Default::default()257 })258}175260/// Run the command specified by `--setup`.261fn run_setup_command(262 shell: &Shell,263 command: &Option<Command<'_>>,264 output_policy: CommandOutputPolicy,265) -> Result<TimingResult> {266 let error_output = "The setup command terminated with a non-zero exit code. \267 Append ' || true' to the command if you are sure that this can be ignored.";176 pub fn run_benchmarks(&mut self) -> Result<()> {177 let shell_spawning_time = mean_shell_spawning_time(178 &self.options.shell,179 self.options.output_style,180 self.options.command_output_policy,181 )?;182269 run_intermediate_command(shell, command, output_policy, error_output)270}183 for (num, cmd) in self.commands.iter().enumerate() {184 self.results185 .push(self.run_benchmark(num, cmd, shell_spawning_time, self.options)?);186272/// Run the command specified by `--prepare`.273fn run_preparation_command(274 shell: &Shell,275 command: &Option<Command<'_>>,276 output_policy: CommandOutputPolicy,277) -> Result<TimingResult> {278 let error_output = "The preparation command terminated with a non-zero exit code. \279 Append ' || true' to the command if you are sure that this can be ignored.";187 // We export (all results so far) after each individual benchmark, because188 // we would risk losing all results if a later benchmark fails.189 self.export_manager190 .write_results(&self.results, self.options.time_unit)?;191 }192281 run_intermediate_command(shell, command, output_policy, error_output)282}193 Ok(())194 }195284/// Run the command specified by `--cleanup`.285fn run_cleanup_command(286 shell: &Shell,287 command: &Option<Command<'_>>,288 output_policy: CommandOutputPolicy,289) -> Result<TimingResult> {290 let error_output = "The cleanup command terminated with a non-zero exit code. \291 Append ' || true' to the command if you are sure that this can be ignored.";196 pub fn print_relative_speed_comparison(&self) {197 if self.options.output_style == OutputStyleOption::Disabled {198 return;199 }200201 if self.results.len() < 2 {293 run_intermediate_command(shell, command, output_policy, error_output)294}202 return;203 }204296/// Run the benchmark for a single shell command297pub fn run_benchmark(298 num: usize,299 cmd: &Command<'_>,300 shell_spawning_time: TimingResult,301 options: &Options,302) -> Result<BenchmarkResult> {303 let command_name = cmd.get_name();304 if options.output_style != OutputStyleOption::Disabled {305 println!(306 "{}{}: {}",307 "Benchmark ".bold(),308 (num + 1).to_string().bold(),309 command_name,310 );311 }205 if let Some(mut annotated_results) = relative_speed::compute(&self.results) {206 annotated_results.sort_by(|l, r| relative_speed::compare_mean_time(l.result, r.result));207313 let mut times_real: Vec<Second> = vec![];314 let mut times_user: Vec<Second> = vec![];315 let mut times_system: Vec<Second> = vec![];316 let mut exit_codes: Vec<Option<i32>> = vec![];317 let mut all_succeeded = true;208 let fastest = &annotated_results[0];209 let others = &annotated_results[1..];210319 // Run init command320 let prepare_cmd = options.preparation_command.as_ref().map(|values| {321 let preparation_command = if values.len() == 1 {322 &values[0]323 } else {324 &values[num]325 };326 Command::new_parametrized(None, preparation_command, cmd.get_parameters().clone())327 });211 println!("{}", "Summary".bold());212 println!(" '{}' ran", fastest.result.command.cyan());213329 // Run setup command330 let setup_cmd = options.setup_command.as_ref().map(|setup_command| {331 Command::new_parametrized(None, setup_command, cmd.get_parameters().clone())332 });333 run_setup_command(&options.shell, &setup_cmd, options.command_output_policy)?;334335 // Warmup phase336 if options.warmup_count > 0 {337 let progress_bar = if options.output_style != OutputStyleOption::Disabled {338 Some(get_progress_bar(339 options.warmup_count,340 "Performing warmup runs",341 options.output_style,342 ))214 for item in others {215 println!(216 "{}{} times faster than '{}'",217 format!("{:8.2}", item.relative_speed).bold().green(),218 if let Some(stddev) = item.relative_speed_stddev {219 format!(" ± {}", format!("{:.2}", stddev).green())220 } else {221 "".into()222 },223 &item.result.command.magenta()224 );225 }226 } else {344 None345 };227 eprintln!(228 "{}: The benchmark comparison could not be computed as some benchmark times are zero. \229 This could be caused by background interference during the initial calibration phase \230 of hyperfine, in combination with very fast commands (faster than a few milliseconds). \231 Try to re-run the benchmark on a quiet system. If it does not help, you command is \232 most likely too fast to be accurately benchmarked by hyperfine.",233 "Note".bold().red()234 );235 }236 }237347 for _ in 0..options.warmup_count {348 let _ = run_preparation_command(349 &options.shell,350 &prepare_cmd,351 options.command_output_policy,352 )?;353 let _ = time_shell_command(354 &options.shell,238 fn run_intermediate_command(239 &self,240 command: &Option<Command<'_>>,241 error_output: &'static str,242 ) -> Result<TimingResult> {243 if let Some(ref cmd) = command {244 let res = time_shell_command(245 &self.options.shell,246 cmd,356 options.command_output_policy,357 options.command_failure_action,247 self.options.command_output_policy,248 CmdFailureAction::RaiseError,249 None,359 )?;360 if let Some(bar) = progress_bar.as_ref() {361 bar.inc(1)250 );251 if res.is_err() {252 bail!(error_output);253 }254 return res.map(|r| r.0);255 }364 if let Some(bar) = progress_bar.as_ref() {365 bar.finish_and_clear()366 }256 Ok(TimingResult {257 ..Default::default()258 })259 }260369 // Set up progress bar (and spinner for initial measurement)370 let progress_bar = if options.output_style != OutputStyleOption::Disabled {371 Some(get_progress_bar(372 options.run_bounds.min,373 "Initial time measurement",374 options.output_style,375 ))376 } else {377 None378 };261 /// Run the command specified by `--setup`.262 fn run_setup_command(&self, command: &Option<Command<'_>>) -> Result<TimingResult> {263 let error_output = "The setup command terminated with a non-zero exit code. \264 Append ' || true' to the command if you are sure that this can be ignored.";265380 let prepare_result =381 run_preparation_command(&options.shell, &prepare_cmd, options.command_output_policy)?;266 self.run_intermediate_command(command, error_output)267 }268383 // Initial timing run384 let (res, status) = time_shell_command(385 &options.shell,386 cmd,387 options.command_output_policy,388 options.command_failure_action,389 Some(shell_spawning_time),390 )?;391 let success = status.success();269 /// Run the command specified by `--prepare`.270 fn run_preparation_command(&self, command: &Option<Command<'_>>) -> Result<TimingResult> {271 let error_output = "The preparation command terminated with a non-zero exit code. \272 Append ' || true' to the command if you are sure that this can be ignored.";273393 // Determine number of benchmark runs394 let runs_in_min_time = (options.min_benchmarking_time395 / (res.time_real + prepare_result.time_real + shell_spawning_time.time_real))396 as u64;274 self.run_intermediate_command(command, error_output)275 }276398 let count = {399 let min = cmp::max(runs_in_min_time, options.run_bounds.min);277 /// Run the command specified by `--cleanup`.278 fn run_cleanup_command(&self, command: &Option<Command<'_>>) -> Result<TimingResult> {279 let error_output = "The cleanup command terminated with a non-zero exit code. \280 Append ' || true' to the command if you are sure that this can be ignored.";281401 options402 .run_bounds403 .max404 .as_ref()405 .map(|max| cmp::min(min, *max))406 .unwrap_or(min)407 };282 self.run_intermediate_command(command, error_output)283 }284409 let count_remaining = count - 1;285 /// Run the benchmark for a single shell command286 pub fn run_benchmark(287 &self,288 num: usize,289 cmd: &Command<'_>,290 shell_spawning_time: TimingResult,291 options: &Options,292 ) -> Result<BenchmarkResult> {293 let command_name = cmd.get_name();294 if options.output_style != OutputStyleOption::Disabled {295 println!(296 "{}{}: {}",297 "Benchmark ".bold(),298 (num + 1).to_string().bold(),299 command_name,300 );301 }302411 // Save the first result412 times_real.push(res.time_real);413 times_user.push(res.time_user);414 times_system.push(res.time_system);415 exit_codes.push(extract_exit_code(status));303 let mut times_real: Vec<Second> = vec![];304 let mut times_user: Vec<Second> = vec![];305 let mut times_system: Vec<Second> = vec![];306 let mut exit_codes: Vec<Option<i32>> = vec![];307 let mut all_succeeded = true;308417 all_succeeded = all_succeeded && success;309 // Run init command310 let prepare_cmd = options.preparation_command.as_ref().map(|values| {311 let preparation_command = if values.len() == 1 {312 &values[0]313 } else {314 &values[num]315 };316 Command::new_parametrized(317 None,318 preparation_command,319 cmd.get_parameters().iter().cloned(),320 )321 });322419 // Re-configure the progress bar420 if let Some(bar) = progress_bar.as_ref() {421 bar.set_length(count)422 }423 if let Some(bar) = progress_bar.as_ref() {424 bar.inc(1)425 }323 // Run setup command324 let setup_cmd = options.setup_command.as_ref().map(|setup_command| {325 Command::new_parametrized(None, setup_command, cmd.get_parameters().iter().cloned())326 });327 self.run_setup_command(&setup_cmd)?;328427 // Gather statistics428 for _ in 0..count_remaining {429 run_preparation_command(&options.shell, &prepare_cmd, options.command_output_policy)?;329 // Warmup phase330 if options.warmup_count > 0 {331 let progress_bar = if options.output_style != OutputStyleOption::Disabled {332 Some(get_progress_bar(333 options.warmup_count,334 "Performing warmup runs",335 options.output_style,336 ))337 } else {338 None339 };340431 let msg = {432 let mean = format_duration(mean(&times_real), options.time_unit);433 format!("Current estimate: {}", mean.to_string().green())341 for _ in 0..options.warmup_count {342 let _ = self.run_preparation_command(&prepare_cmd)?;343 let _ = time_shell_command(344 &options.shell,345 cmd,346 options.command_output_policy,347 options.command_failure_action,348 None,349 )?;350 if let Some(bar) = progress_bar.as_ref() {351 bar.inc(1)352 }353 }354 if let Some(bar) = progress_bar.as_ref() {355 bar.finish_and_clear()356 }357 }358359 // Set up progress bar (and spinner for initial measurement)360 let progress_bar = if options.output_style != OutputStyleOption::Disabled {361 Some(get_progress_bar(362 options.run_bounds.min,363 "Initial time measurement",364 options.output_style,365 ))366 } else {367 None368 };369436 if let Some(bar) = progress_bar.as_ref() {437 bar.set_message(msg.to_owned())438 }370 let prepare_result = self.run_preparation_command(&prepare_cmd)?;371372 // Initial timing run373 let (res, status) = time_shell_command(374 &options.shell,375 cmd,376 options.command_output_policy,
1 unmodified line
378 Some(shell_spawning_time),379 )?;380 let success = status.success();381382 // Determine number of benchmark runs383 let runs_in_min_time = (options.min_benchmarking_time384 / (res.time_real + prepare_result.time_real + shell_spawning_time.time_real))385 as u64;386387 let count = {388 let min = cmp::max(runs_in_min_time, options.run_bounds.min);389390 options391 .run_bounds392 .max393 .as_ref()394 .map(|max| cmp::min(min, *max))395 .unwrap_or(min)396 };397398 let count_remaining = count - 1;399400 // Save the first result401 times_real.push(res.time_real);402 times_user.push(res.time_user);403 times_system.push(res.time_system);404 exit_codes.push(extract_exit_code(status));405406 all_succeeded = all_succeeded && success;407408 // Re-configure the progress bar409 if let Some(bar) = progress_bar.as_ref() {410 bar.set_length(count)411 }412 if let Some(bar) = progress_bar.as_ref() {413 bar.inc(1)414 }459 }415461 if let Some(bar) = progress_bar.as_ref() {462 bar.finish_and_clear()463 }416 // Gather statistics417 for _ in 0..count_remaining {418 self.run_preparation_command(&prepare_cmd)?;419465 // Compute statistical quantities466 let t_num = times_real.len();467 let t_mean = mean(&times_real);468 let t_stddev = if times_real.len() > 1 {469 Some(standard_deviation(&times_real, Some(t_mean)))470 } else {471 None472 };473 let t_median = median(&times_real);474 let t_min = min(&times_real);475 let t_max = max(&times_real);420 let msg = {421 let mean = format_duration(mean(&times_real), options.time_unit);422 format!("Current estimate: {}", mean.to_string().green())423 };424477 let user_mean = mean(&times_user);478 let system_mean = mean(&times_system);425 if let Some(bar) = progress_bar.as_ref() {426 bar.set_message(msg.to_owned())427 }428480 // Formatting and console output481 let (mean_str, time_unit) = format_duration_unit(t_mean, options.time_unit);482 let min_str = format_duration(t_min, Some(time_unit));483 let max_str = format_duration(t_max, Some(time_unit));484 let num_str = format!("{} runs", t_num);429 let (res, status) = time_shell_command(430 &options.shell,431 cmd,432 options.command_output_policy,433 options.command_failure_action,434 Some(shell_spawning_time),435 )?;436 let success = status.success();437486 let user_str = format_duration(user_mean, Some(time_unit));487 let system_str = format_duration(system_mean, Some(time_unit));438 times_real.push(res.time_real);439 times_user.push(res.time_user);440 times_system.push(res.time_system);441 exit_codes.push(extract_exit_code(status));442489 if options.output_style != OutputStyleOption::Disabled {490 if times_real.len() == 1 {491 println!(492 " Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",493 "abs".green().bold(),494 mean_str.green().bold(),495 " ".to_string(), // alignment496 user_str.blue(),497 system_str.blue()498 );443 all_succeeded = all_succeeded && success;444445 if let Some(bar) = progress_bar.as_ref() {446 bar.inc(1)447 }448 }449450 if let Some(bar) = progress_bar.as_ref() {451 bar.finish_and_clear()452 }453454 // Compute statistical quantities455 let t_num = times_real.len();456 let t_mean = mean(&times_real);457 let t_stddev = if times_real.len() > 1 {458 Some(standard_deviation(&times_real, Some(t_mean)))459 } else {500 let stddev_str = format_duration(t_stddev.unwrap(), Some(time_unit));460 None461 };462 let t_median = median(&times_real);463 let t_min = min(&times_real);464 let t_max = max(&times_real);465502 println!(503 " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",504 "mean".green().bold(),505 "σ".green(),506 mean_str.green().bold(),507 stddev_str.green(),508 user_str.blue(),509 system_str.blue()510 );466 let user_mean = mean(&times_user);467 let system_mean = mean(&times_system);468469 // Formatting and console output470 let (mean_str, time_unit) = format_duration_unit(t_mean, options.time_unit);471 let min_str = format_duration(t_min, Some(time_unit));472 let max_str = format_duration(t_max, Some(time_unit));473 let num_str = format!("{} runs", t_num);474475 let user_str = format_duration(user_mean, Some(time_unit));476 let system_str = format_duration(system_mean, Some(time_unit));477478 if options.output_style != OutputStyleOption::Disabled {479 if times_real.len() == 1 {480 println!(481 " Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",482 "abs".green().bold(),483 mean_str.green().bold(),484 " ".to_string(), // alignment485 user_str.blue(),486 system_str.blue()487 );488 } else {489 let stddev_str = format_duration(t_stddev.unwrap(), Some(time_unit));490491 println!(492 " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",493 "mean".green().bold(),494 "σ".green(),495 mean_str.green().bold(),496 stddev_str.green(),497 user_str.blue(),498 system_str.blue()499 );500512 println!(513 " Range ({} … {}): {:>8} … {:>8} {}",514 "min".cyan(),515 "max".purple(),516 min_str.cyan(),517 max_str.purple(),518 num_str.dimmed()519 );501 println!(502 " Range ({} … {}): {:>8} … {:>8} {}",503 "min".cyan(),504 "max".purple(),505 min_str.cyan(),506 max_str.purple(),507 num_str.dimmed()508 );509 }510 }521 }511523 // Warnings524 let mut warnings = vec![];512 // Warnings513 let mut warnings = vec![];514526 // Check execution time527 if times_real.iter().any(|&t| t < MIN_EXECUTION_TIME) {528 warnings.push(Warnings::FastExecutionTime);529 }515 // Check execution time516 if times_real.iter().any(|&t| t < MIN_EXECUTION_TIME) {517 warnings.push(Warnings::FastExecutionTime);518 }519531 // Check programm exit codes532 if !all_succeeded {533 warnings.push(Warnings::NonZeroExitCode);534 }520 // Check programm exit codes521 if !all_succeeded {522 warnings.push(Warnings::NonZeroExitCode);523 }524536 // Run outlier detection537 let scores = modified_zscores(&times_real);538 if scores[0] > OUTLIER_THRESHOLD {539 warnings.push(Warnings::SlowInitialRun(times_real[0]));540 } else if scores.iter().any(|&s| s.abs() > OUTLIER_THRESHOLD) {541 warnings.push(Warnings::OutliersDetected);542 }525 // Run outlier detection526 let scores = modified_zscores(&times_real);527 if scores[0] > OUTLIER_THRESHOLD {528 warnings.push(Warnings::SlowInitialRun(times_real[0]));529 } else if scores.iter().any(|&s| s.abs() > OUTLIER_THRESHOLD) {530 warnings.push(Warnings::OutliersDetected);531 }532544 if !warnings.is_empty() {545 eprintln!(" ");533 if !warnings.is_empty() {534 eprintln!(" ");535547 for warning in &warnings {548 eprintln!(" {}: {}", "Warning".yellow(), warning);536 for warning in &warnings {537 eprintln!(" {}: {}", "Warning".yellow(), warning);538 }539 }550 }540552 if options.output_style != OutputStyleOption::Disabled {553 println!(" ");554 }541 if options.output_style != OutputStyleOption::Disabled {542 println!(" ");543 }544556 // Run cleanup command557 let cleanup_cmd = options.cleanup_command.as_ref().map(|cleanup_command| {558 Command::new_parametrized(None, cleanup_command, cmd.get_parameters().clone())559 });560 run_cleanup_command(&options.shell, &cleanup_cmd, options.command_output_policy)?;545 // Run cleanup command546 let cleanup_cmd = options.cleanup_command.as_ref().map(|cleanup_command| {547 Command::new_parametrized(None, cleanup_command, cmd.get_parameters().iter().cloned())548 });549 self.run_cleanup_command(&cleanup_cmd)?;550562 Ok(BenchmarkResult {563 command: command_name,564 mean: t_mean,565 stddev: t_stddev,566 median: t_median,567 user: user_mean,568 system: system_mean,569 min: t_min,570 max: t_max,571 times: Some(times_real),572 exit_codes,573 parameters: cmd574 .get_parameters()575 .iter()576 .map(|(name, value)| ((*name).to_string(), value.to_string()))577 .collect(),578 })551 Ok(BenchmarkResult {552 command: command_name,553 mean: t_mean,554 stddev: t_stddev,555 median: t_median,556 user: user_mean,557 system: system_mean,558 min: t_min,559 max: t_max,560 times: Some(times_real),561 exit_codes,562 parameters: cmd563 .get_parameters()564 .iter()565 .map(|(name, value)| ((*name).to_string(), value.to_string()))566 .collect(),567 })568 }569}
modified:src/parameter/mod.rs+2 added
15 unmodified lines
16 ParameterValue::Numeric(value) => value.to_string(),17 }18 }19}2021pub type ParameterNameAndValue<'a> = (&'a str, ParameterValue);
modified:src/command.rs+9 added-6 removed
2 unmodified lines
3use std::str::FromStr;45use crate::{6 error::{OptionsError, ParameterScanError},7 parameter::range_step::{Numeric, RangeStep},7 parameter::{8 range_step::{Numeric, RangeStep},9 ParameterNameAndValue,10 },11};1213use clap::ArgMatches;14
13 unmodified lines
28 /// The command that should be executed (without parameter substitution)29 expression: &'a str,3031 /// Zero or more parameter values.29 parameters: Vec<(&'a str, ParameterValue)>,32 parameters: Vec<ParameterNameAndValue<'a>>,33}3435impl<'a> Command<'a> {36 pub fn new(name: Option<&'a str>, expression: &'a str) -> Command<'a> {
6 unmodified lines
4344 pub fn new_parametrized(45 name: Option<&'a str>,46 expression: &'a str,44 parameters: Vec<(&'a str, ParameterValue)>,47 parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,48 ) -> Command<'a> {49 Command {50 name,51 expression,49 parameters,52 parameters: parameters.into_iter().collect(),53 }54 }5556 pub fn get_name(&self) -> String {
6 unmodified lines
63 pub fn get_shell_command(&self) -> String {64 self.replace_parameters_in(self.expression)65 }6664 pub fn get_parameters(&self) -> &Vec<(&'a str, ParameterValue)> {67 pub fn get_parameters(&self) -> &[(&'a str, ParameterValue)] {68 &self.parameters69 }7071 fn replace_parameters_in(&self, original: &str) -> String {
96 unmodified lines
168 .copied();169 i += 1;170171 let (command_index, params_indices) = index.split_first().unwrap();169 let parameters = param_names_and_values172 let parameters: Vec<_> = param_names_and_values173 .iter()174 .zip(params_indices)175 .map(|((name, values), i)| (*name, ParameterValue::Text(values[*i].clone())))176 .collect();
346 unmodified lines