use set and settrue

This commit is contained in:
Benjamin Rombaut authored and David Peter committed 2022-11-19 15:13:30 +01:00
1 parent 5fcb7166a9
commit 27ec9e22d8
2 files changed
+28 -52

No files matched your search

+24 -48
View File
@@ -36,9 +36,8 @@ fn build_command() -> Command<'static> {
Arg::new("warmup") Arg::new("warmup")
.long("warmup") .long("warmup")
.short('w') .short('w')
.takes_value(true)
.value_name("NUM") .value_name("NUM")
.action(ArgAction::StoreValue) .action(ArgAction::Set)
.help( .help(
"Perform NUM warmup runs before the actual benchmark. This can be used \ "Perform NUM warmup runs before the actual benchmark. This can be used \
to fill (disk) caches for I/O-heavy programs.", to fill (disk) caches for I/O-heavy programs.",
@@ -48,8 +47,7 @@ fn build_command() -> Command<'static> {
Arg::new("min-runs") Arg::new("min-runs")
.long("min-runs") .long("min-runs")
.short('m') .short('m')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("NUM") .value_name("NUM")
.help("Perform at least NUM runs for each command (default: 10)."), .help("Perform at least NUM runs for each command (default: 10)."),
) )
@@ -57,8 +55,7 @@ fn build_command() -> Command<'static> {
Arg::new("max-runs") Arg::new("max-runs")
.long("max-runs") .long("max-runs")
.short('M') .short('M')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("NUM") .value_name("NUM")
.help("Perform at most NUM runs for each command. By default, there is no limit."), .help("Perform at most NUM runs for each command. By default, there is no limit."),
) )
@@ -67,8 +64,7 @@ fn build_command() -> Command<'static> {
.long("runs") .long("runs")
.conflicts_with_all(&["max-runs", "min-runs"]) .conflicts_with_all(&["max-runs", "min-runs"])
.short('r') .short('r')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("NUM") .value_name("NUM")
.help("Perform exactly NUM runs for each command. If this option is not specified, \ .help("Perform exactly NUM runs for each command. If this option is not specified, \
hyperfine automatically determines the number of runs."), hyperfine automatically determines the number of runs."),
@@ -77,9 +73,7 @@ fn build_command() -> Command<'static> {
Arg::new("setup") Arg::new("setup")
.long("setup") .long("setup")
.short('s') .short('s')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.number_of_values(1)
.value_name("CMD") .value_name("CMD")
.help( .help(
"Execute CMD before each set of timing runs. This is useful for \ "Execute CMD before each set of timing runs. This is useful for \
@@ -92,9 +86,7 @@ fn build_command() -> Command<'static> {
Arg::new("prepare") Arg::new("prepare")
.long("prepare") .long("prepare")
.short('p') .short('p')
.takes_value(true) .action(ArgAction::Append)
.action(ArgAction::StoreValue)
.multiple_occurrences(true)
.number_of_values(1) .number_of_values(1)
.value_name("CMD") .value_name("CMD")
.help( .help(
@@ -109,8 +101,7 @@ fn build_command() -> Command<'static> {
Arg::new("cleanup") Arg::new("cleanup")
.long("cleanup") .long("cleanup")
.short('c') .short('c')
.action(ArgAction::StoreValue) .action(ArgAction::Set)
.takes_value(true)
.value_name("CMD") .value_name("CMD")
.help( .help(
"Execute CMD after the completion of all benchmarking \ "Execute CMD after the completion of all benchmarking \
@@ -123,8 +114,7 @@ fn build_command() -> Command<'static> {
Arg::new("parameter-scan") Arg::new("parameter-scan")
.long("parameter-scan") .long("parameter-scan")
.short('P') .short('P')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_names(&["VAR", "MIN", "MAX"]) .value_names(&["VAR", "MIN", "MAX"])
.help( .help(
@@ -142,8 +132,7 @@ fn build_command() -> Command<'static> {
Arg::new("parameter-step-size") Arg::new("parameter-step-size")
.long("parameter-step-size") .long("parameter-step-size")
.short('D') .short('D')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_names(&["DELTA"]) .value_names(&["DELTA"])
.requires("parameter-scan") .requires("parameter-scan")
.help( .help(
@@ -157,9 +146,7 @@ fn build_command() -> Command<'static> {
Arg::new("parameter-list") Arg::new("parameter-list")
.long("parameter-list") .long("parameter-list")
.short('L') .short('L')
.takes_value(true) .action(ArgAction::Append)
.action(ArgAction::StoreValue)
.multiple_occurrences(true)
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_names(&["VAR", "VALUES"]) .value_names(&["VAR", "VALUES"])
.conflicts_with_all(&["parameter-scan", "parameter-step-size"]) .conflicts_with_all(&["parameter-scan", "parameter-step-size"])
@@ -175,8 +162,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("style") Arg::new("style")
.long("style") .long("style")
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("TYPE") .value_name("TYPE")
.value_parser(["auto", "basic", "full", "nocolor", "color", "none"]) .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])
.help( .help(
@@ -192,8 +178,7 @@ fn build_command() -> Command<'static> {
Arg::new("shell") Arg::new("shell")
.long("shell") .long("shell")
.short('S') .short('S')
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("SHELL") .value_name("SHELL")
.overrides_with("shell") .overrides_with("shell")
.help("Set the shell to use for executing benchmarked commands. This can be the \ .help("Set the shell to use for executing benchmarked commands. This can be the \
@@ -207,14 +192,14 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("no-shell") Arg::new("no-shell")
.short('N') .short('N')
.action(ArgAction::IncOccurrence) .action(ArgAction::SetTrue)
.conflicts_with_all(&["shell", "debug-mode"]) .conflicts_with_all(&["shell", "debug-mode"])
.help("An alias for '--shell=none'.") .help("An alias for '--shell=none'.")
) )
.arg( .arg(
Arg::new("ignore-failure") Arg::new("ignore-failure")
.long("ignore-failure") .long("ignore-failure")
.action(ArgAction::IncOccurrence) .action(ArgAction::SetTrue)
.short('i') .short('i')
.help("Ignore non-zero exit codes of the benchmarked programs."), .help("Ignore non-zero exit codes of the benchmarked programs."),
) )
@@ -222,8 +207,7 @@ fn build_command() -> Command<'static> {
Arg::new("time-unit") Arg::new("time-unit")
.long("time-unit") .long("time-unit")
.short('u') .short('u')
.action(ArgAction::StoreValue) .action(ArgAction::Set)
.takes_value(true)
.value_name("UNIT") .value_name("UNIT")
.value_parser(["millisecond", "second"]) .value_parser(["millisecond", "second"])
.help("Set the time unit to be used. Possible values: millisecond, second. \ .help("Set the time unit to be used. Possible values: millisecond, second. \
@@ -233,8 +217,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("export-asciidoc") Arg::new("export-asciidoc")
.long("export-asciidoc") .long("export-asciidoc")
.action(ArgAction::StoreValue) .action(ArgAction::Set)
.takes_value(true)
.value_name("FILE") .value_name("FILE")
.help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \ .help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \
The output time unit can be changed using the --time-unit option."), The output time unit can be changed using the --time-unit option."),
@@ -242,8 +225,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("export-csv") Arg::new("export-csv")
.long("export-csv") .long("export-csv")
.action(ArgAction::StoreValue) .action(ArgAction::Set)
.takes_value(true)
.value_name("FILE") .value_name("FILE")
.help("Export the timing summary statistics as CSV to the given FILE. If you need \ .help("Export the timing summary statistics as CSV to the given FILE. If you need \
the timing results for each individual run, use the JSON export format. \ the timing results for each individual run, use the JSON export format. \
@@ -252,7 +234,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("export-json") Arg::new("export-json")
.long("export-json") .long("export-json")
.action(ArgAction::StoreValue) .action(ArgAction::Set)
.value_name("FILE") .value_name("FILE")
.help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE. \ .help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE. \
The output time unit is always seconds"), The output time unit is always seconds"),
@@ -260,8 +242,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("export-markdown") Arg::new("export-markdown")
.long("export-markdown") .long("export-markdown")
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("FILE") .value_name("FILE")
.help("Export the timing summary statistics as a Markdown table to the given FILE. \ .help("Export the timing summary statistics as a Markdown table to the given FILE. \
The output time unit can be changed using the --time-unit option."), The output time unit can be changed using the --time-unit option."),
@@ -269,8 +250,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("export-orgmode") Arg::new("export-orgmode")
.long("export-orgmode") .long("export-orgmode")
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("FILE") .value_name("FILE")
.help("Export the timing summary statistics as a Emacs org-mode table to the given FILE. \ .help("Export the timing summary statistics as a Emacs org-mode table to the given FILE. \
The output time unit can be changed using the --time-unit option."), The output time unit can be changed using the --time-unit option."),
@@ -291,8 +271,7 @@ fn build_command() -> Command<'static> {
Arg::new("output") Arg::new("output")
.long("output") .long("output")
.conflicts_with("show-output") .conflicts_with("show-output")
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.value_name("WHERE") .value_name("WHERE")
.help( .help(
"Control where the output of the benchmark is redirected. <WHERE> can be:\n\n\ "Control where the output of the benchmark is redirected. <WHERE> can be:\n\n\
@@ -309,9 +288,7 @@ fn build_command() -> Command<'static> {
Arg::new("command-name") Arg::new("command-name")
.long("command-name") .long("command-name")
.short('n') .short('n')
.takes_value(true) .action(ArgAction::Append)
.action(ArgAction::StoreValue)
.multiple_occurrences(true)
.number_of_values(1) .number_of_values(1)
.value_name("NAME") .value_name("NAME")
.help("Give a meaningful name to a command. This can be specified multiple times \ .help("Give a meaningful name to a command. This can be specified multiple times \
@@ -322,8 +299,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("min-benchmarking-time") Arg::new("min-benchmarking-time")
.long("min-benchmarking-time") .long("min-benchmarking-time")
.takes_value(true) .action(ArgAction::Set)
.action(ArgAction::StoreValue)
.hide(true) .hide(true)
.help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \ .help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \
benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \ benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \
@@ -332,7 +308,7 @@ fn build_command() -> Command<'static> {
.arg( .arg(
Arg::new("debug-mode") Arg::new("debug-mode")
.long("debug-mode") .long("debug-mode")
.action(ArgAction::IncOccurrence) .action(ArgAction::SetTrue)
.hide(true) .hide(true)
.help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.") .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.")
) )
+4 -4
View File
@@ -268,7 +268,7 @@ impl Options {
options.cleanup_command = matches.get_one::<String>("cleanup").map(String::from); options.cleanup_command = matches.get_one::<String>("cleanup").map(String::from);
options.command_output_policy = if matches.contains_id("show-output") { options.command_output_policy = if matches.get_flag("show-output") {
CommandOutputPolicy::Inherit CommandOutputPolicy::Inherit
} else if let Some(output) = matches.get_one::<String>("output").map(|s| s.as_str()) { } else if let Some(output) = matches.get_one::<String>("output").map(|s| s.as_str()) {
match output { match output {
@@ -322,10 +322,10 @@ impl Options {
OutputStyleOption::Disabled => {} OutputStyleOption::Disabled => {}
}; };
options.executor_kind = if matches.contains_id("no-shell") { options.executor_kind = if matches.get_flag("no-shell") {
ExecutorKind::Raw ExecutorKind::Raw
} else { } else {
match (matches.contains_id("debug-mode"), matches.get_one::<String>("shell")) { match (matches.get_flag("debug-mode"), matches.get_one::<String>("shell")) {
(false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()), (false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()),
(false, Some(shell)) if shell == "none" => ExecutorKind::Raw, (false, Some(shell)) if shell == "none" => ExecutorKind::Raw,
(false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?), (false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?),
@@ -335,7 +335,7 @@ impl Options {
} }
}; };
if matches.contains_id("ignore-failure") { if matches.get_flag("ignore-failure") {
options.command_failure_action = CmdFailureAction::Ignore; options.command_failure_action = CmdFailureAction::Ignore;
} }