cli.rs
This file
Path
src/cli.rs
318 lines · 14.3 KiB · Rust
Last changed by
use wrap_helpBenjamin Rombautbefore adoption17aca87
History of this fileTake it
Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 1–2why, one step back1use std::ffi::OsString;2update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 3why, one step back3use clap::{crate_version, Arg, ArgMatches, Command, builder::NonEmptyStringValueParser, ArgAction};Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 4–14why, one step back45pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches6where7 I: IntoIterator<Item = T>,8 T: Into<OsString> + Clone + 'a,9{10 let command = build_command();11 command.get_matches_from(args)12}1314/// Build the clap command for parsing command line argumentsupdate to clap 4Benjamin Rombautbefore adoption8d38ef3
line 15why, one step back15fn build_command() -> Command {Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 16–20why, one step back16 Command::new("hyperfine")17 .version(crate_version!())18 .next_line_help(true)19 .hide_possible_values(true)20 .about("A command-line benchmarking tool.")use wrap_helpBenjamin Rombautbefore adoption17aca87
line 21why, one step back21 .help_expected(true)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 22–23why, one step back22 .arg(23 Arg::new("command")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 24–28why, one step back24 .help("The command to benchmark. This can be the name of an executable, a command \25 line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \26 The latter is only available if the shell is not explicitly disabled via \27 '--shell=none'. If multiple commands are given, hyperfine will show a \28 comparison of the respective runtimes.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 29why, one step back29 .required(true)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 30why, one step back30 .action(ArgAction::Append)add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 31why, one step back31 .value_parser(NonEmptyStringValueParser::new()),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 32–37why, one step back32 )33 .arg(34 Arg::new("warmup")35 .long("warmup")36 .short('w')37 .value_name("NUM")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 38why, one step back38 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 39–47why, one step back39 .help(40 "Perform NUM warmup runs before the actual benchmark. This can be used \41 to fill (disk) caches for I/O-heavy programs.",42 ),43 )44 .arg(45 Arg::new("min-runs")46 .long("min-runs")47 .short('m')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 48why, one step back48 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 49–55why, one step back49 .value_name("NUM")50 .help("Perform at least NUM runs for each command (default: 10)."),51 )52 .arg(53 Arg::new("max-runs")54 .long("max-runs")55 .short('M')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 56why, one step back56 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 57–64why, one step back57 .value_name("NUM")58 .help("Perform at most NUM runs for each command. By default, there is no limit."),59 )60 .arg(61 Arg::new("runs")62 .long("runs")63 .conflicts_with_all(&["max-runs", "min-runs"])64 .short('r')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 65why, one step back65 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 66–73why, one step back66 .value_name("NUM")67 .help("Perform exactly NUM runs for each command. If this option is not specified, \68 hyperfine automatically determines the number of runs."),69 )70 .arg(71 Arg::new("setup")72 .long("setup")73 .short('s')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 74why, one step back74 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 75–86why, one step back75 .value_name("CMD")76 .help(77 "Execute CMD before each set of timing runs. This is useful for \78 compiling your software with the provided parameters, or to do any \79 other work that should happen once before a series of benchmark runs, \80 not every time as would happen with the --prepare option."81 ),82 )83 .arg(84 Arg::new("prepare")85 .long("prepare")86 .short('p')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 87why, one step back87 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 88why, one step back88 .num_args(1)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 89–101why, one step back89 .value_name("CMD")90 .help(91 "Execute CMD before each timing run. This is useful for \92 clearing disk caches, for example.\nThe --prepare option can \93 be specified once for all commands or multiple times, once for \94 each command. In the latter case, each preparation command will \95 be run prior to the corresponding benchmark command.",96 ),97 )98 .arg(99 Arg::new("cleanup")100 .long("cleanup")101 .short('c')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 102why, one step back102 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 103–114why, one step back103 .value_name("CMD")104 .help(105 "Execute CMD after the completion of all benchmarking \106 runs for each individual command to be benchmarked. \107 This is useful if the commands to be benchmarked produce \108 artifacts that need to be cleaned up."109 ),110 )111 .arg(112 Arg::new("parameter-scan")113 .long("parameter-scan")114 .short('P')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 115why, one step back115 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 116–132why, one step back116 .allow_hyphen_values(true)117 .value_names(&["VAR", "MIN", "MAX"])118 .help(119 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \120 string '{VAR}' in each command by the current parameter value.\n\n \121 Example: hyperfine -P threads 1 8 'make -j {threads}'\n\n\122 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\123 To have the value increase following different patterns, use shell arithmetics.\n\n \124 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\125 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\126 The exact syntax may vary depending on your shell and OS."127 ),128 )129 .arg(130 Arg::new("parameter-step-size")131 .long("parameter-step-size")132 .short('D')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 133why, one step back133 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 134–146why, one step back134 .value_names(&["DELTA"])135 .requires("parameter-scan")136 .help(137 "This argument requires --parameter-scan to be specified as well. \138 Traverse the range MIN..MAX in steps of DELTA.\n\n \139 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\140 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",141 ),142 )143 .arg(144 Arg::new("parameter-list")145 .long("parameter-list")146 .short('L')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 147why, one step back147 .action(ArgAction::Append)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 148–162why, one step back148 .allow_hyphen_values(true)149 .value_names(&["VAR", "VALUES"])150 .conflicts_with_all(&["parameter-scan", "parameter-step-size"])151 .help(152 "Perform benchmark runs for each value in the comma-separated list VALUES. \153 Replaces the string '{VAR}' in each command by the current parameter value\154 .\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\155 This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\156 The option can be specified multiple times to run benchmarks for all \157 possible parameter combinations.\n"158 ),159 )160 .arg(161 Arg::new("style")162 .long("style")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 163why, one step back163 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 164why, one step back164 .value_name("TYPE")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 165why, one step back165 .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 166–178why, one step back166 .help(167 "Set output style type (default: auto). Set this to 'basic' to disable output \168 coloring and interactive elements. Set it to 'full' to enable all effects \169 even if no interactive terminal was detected. Set this to 'nocolor' to \170 keep the interactive output without any colors. Set this to 'color' to keep \171 the colors without any interactive output. Set this to 'none' to disable all \172 the output of the tool.",173 ),174 )175 .arg(176 Arg::new("shell")177 .long("shell")178 .short('S')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 179why, one step back179 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 180–181why, one step back180 .value_name("SHELL")181 .overrides_with("shell")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 182–184why, one step back182 .help("Set the shell to use for executing benchmarked commands. This can be the \183 name or the path to the shell executable, or a full command line \184 like \"bash --norc\". It can also be set to \"default\" to explicitly select \Update warning textDavid Peterbefore adoption65932dd
line 185why, one step back185 the default shell on this platform. Finally, this can also be set to \Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 186–192why, one step back186 \"none\" to disable the shell. In this case, commands will be executed \187 directly. They can still have arguments, but more complex things like \188 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")189 )190 .arg(191 Arg::new("no-shell")192 .short('N')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 193why, one step back193 .action(ArgAction::SetTrue)Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 194–195why, one step back194 .conflicts_with_all(&["shell", "debug-mode"])195 .help("An alias for '--shell=none'.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 196–199why, one step back196 )197 .arg(198 Arg::new("ignore-failure")199 .long("ignore-failure")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 200why, one step back200 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 201–207why, one step back201 .short('i')202 .help("Ignore non-zero exit codes of the benchmarked programs."),203 )204 .arg(205 Arg::new("time-unit")206 .long("time-unit")207 .short('u')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 208why, one step back208 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 209why, one step back209 .value_name("UNIT")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 210why, one step back210 .value_parser(["millisecond", "second"])Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
lines 211–212why, one step back211 .help("Set the time unit to be used. Possible values: millisecond, second. \212 If the option is not given, the time unit is determined automatically. \Make --time-unit help text more generic.Engineer-of-Efficiencybefore adoptionedb29f4
line 213why, one step back213 This option affects the standard output as well as all export formats except for CSV and JSON."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 214–217why, one step back214 )215 .arg(216 Arg::new("export-asciidoc")217 .long("export-asciidoc")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 218why, one step back218 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 219why, one step back219 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 220why, one step back220 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 221why, one step back221 The output time unit can be changed using the --time-unit option."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 222–225why, one step back222 )223 .arg(224 Arg::new("export-csv")225 .long("export-csv")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 226why, one step back226 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 227–228why, one step back227 .value_name("FILE")228 .help("Export the timing summary statistics as CSV to the given FILE. If you need \Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 229why, one step back229 the timing results for each individual run, use the JSON export format. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 230why, one step back230 The output time unit is always seconds."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 231–234why, one step back231 )232 .arg(233 Arg::new("export-json")234 .long("export-json")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 235why, one step back235 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 236why, one step back236 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 237why, one step back237 .help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE. \Remove possible ambiguity Engineer-of-Efficiencybefore adoptiona217f3f
line 238why, one step back238 The output time unit is always seconds"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 239–242why, one step back239 )240 .arg(241 Arg::new("export-markdown")242 .long("export-markdown")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 243why, one step back243 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 244why, one step back244 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 245why, one step back245 .help("Export the timing summary statistics as a Markdown table to the given FILE. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 246why, one step back246 The output time unit can be changed using the --time-unit option."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 247–248why, one step back247 )248 .arg(Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 249–250why, one step back249 Arg::new("export-orgmode")250 .long("export-orgmode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 251why, one step back251 .action(ArgAction::Set)Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 252why, one step back252 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 253why, one step back253 .help("Export the timing summary statistics as a Emacs org-mode table to the given FILE. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 254why, one step back254 The output time unit can be changed using the --time-unit option."),Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 255–256why, one step back255 )256 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 257–258why, one step back257 Arg::new("show-output")258 .long("show-output")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 259why, one step back259 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 260–268why, one step back260 .conflicts_with("style")261 .help(262 "Print the stdout and stderr of the benchmark instead of suppressing it. \263 This will increase the time it takes for benchmarks to run, \264 so it should only be used for debugging purposes or \265 when trying to benchmark output speed.",266 ),267 )268 .arg(Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 269–271why, one step back269 Arg::new("output")270 .long("output")271 .conflicts_with("show-output")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 272why, one step back272 .action(ArgAction::Set)Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 273–274why, one step back273 .value_name("WHERE")274 .help(Clarify --output's help textTavian Barnesbefore adoptiondfd1046
lines 275–280why, one step back275 "Control where the output of the benchmark is redirected. <WHERE> can be:\n\n\276 null: Redirect output to /dev/null (the default). \277 Note that some programs like 'grep' detect when standard output is /dev/null \278 and apply certain optimizations. To avoid that, consider using \279 '--output=pipe'.\n\n\280 pipe: Feed the output through a pipe before discarding it.\n\n\Add --output=inherit as an alias for --show-outputTavian Barnesbefore adoptionecee9df
line 281why, one step back281 inherit: Don't redirect the output at all (same as '--show-output').\n\n\Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 282–285why, one step back282 <FILE>: Write the output to the given file.",283 ),284 )285 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 286–288why, one step back286 Arg::new("command-name")287 .long("command-name")288 .short('n')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 289why, one step back289 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 290why, one step back290 .num_args(1)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 291–294why, one step back291 .value_name("NAME")292 .help("Give a meaningful name to a command. This can be specified multiple times \293 if several commands are benchmarked."),294 )Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3
lines 295–299why, one step back295 // This option is hidden for now, as it is not yet clear yet if we want to 'stabilize' this,296 // see discussion in https://github.com/sharkdp/hyperfine/issues/527297 .arg(298 Arg::new("min-benchmarking-time")299 .long("min-benchmarking-time")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 300why, one step back300 .action(ArgAction::Set)Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3
lines 301–305why, one step back301 .hide(true)302 .help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \303 benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \304 `--runs` option.")305 )Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 306–308why, one step back306 .arg(307 Arg::new("debug-mode")308 .long("debug-mode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 309why, one step back309 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 310why, one step back310 .hide(true)Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 311why, one step back311 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 312–318why, one step back312 )313}314315#[test]316fn verify_app() {317 build_command().debug_assert();318}