Implement basic --parameter-list with naive list parsing

This commit is contained in:
Hasan Ibraheem 2019-10-17 12:27:32 -04:00 committed by David Peter
parent 538691e999
commit 4a5d08ddc2
2 changed files with 31 additions and 0 deletions

View File

@ -129,6 +129,21 @@ fn build_app() -> App<'static, 'static> {
This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",
),
)
.arg(
Arg::with_name("parameter-list")
.long("parameter-list")
.short("L")
.takes_value(true)
.allow_hyphen_values(true)
.value_names(&["VAR", "VALUES"])
.conflicts_with("parameter-scan")
.help(
"Perform benchmark runs for each value in the comma-seperated list VALUES. \
Replaces the string '{VAR}' in each command by the current parameter value\
.\n\nExample: hyperfine -L threads 1,2,4 'make -j {threads}'\n\n\
This performs benchmarks for 'make -j 1', 'make -j 2', and 'make -j 4'.",
),
)
.arg(
Arg::with_name("style")
.long("style")

View File

@ -208,6 +208,22 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec<Command<'a>> {
Ok(commands) => commands,
Err(e) => error(e.description()),
}
} else if let Some(mut args) = matches.values_of("parameter-list") {
let param_name = args.next().unwrap();
let param_list_str = args.next().unwrap();
let param_list = param_list_str.split(',').collect::<Vec<&str>>();
let command_list = command_strings.collect::<Vec<&str>>();
let mut commands = Vec::with_capacity(param_list.len() * command_list.len());
for value in param_list {
for cmd in &command_list {
commands.push(Command::new_parametrized(cmd, param_name, value.to_string()));
}
}
commands
} else {
command_strings.map(Command::new).collect()
}