cli.rs
This file
Path
src/cli.rs
423 lines · 19.2 KiB · Rust
Last changed by
Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
History of this fileTake it
The walk stopped after 200 commits: lines older than c44aa1d point at it.
Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 1–4why, one step back1use std::ffi::OsString;23use clap::{4 builder::NonEmptyStringValueParser, crate_version, Arg, ArgAction, ArgMatches, Command,Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 5why, one step back5 ValueHint,Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 6–24why, one step back6};78pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches9where10 I: IntoIterator<Item = T>,11 T: Into<OsString> + Clone + 'a,12{13 let command = build_command();14 command.get_matches_from(args)15}1617/// Build the clap command for parsing command line arguments18fn build_command() -> Command {19 Command::new("hyperfine")20 .version(crate_version!())21 .next_line_help(true)22 .hide_possible_values(true)23 .about("A command-line benchmarking tool.")24 .help_expected(true)Use max. term width, not term widthDavid Peterbefore adoptionfbe9ca6
line 25why, one step back25 .max_term_width(80)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 26–34why, one step back26 .arg(27 Arg::new("command")28 .help("The command to benchmark. This can be the name of an executable, a command \29 line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \30 The latter is only available if the shell is not explicitly disabled via \31 '--shell=none'. If multiple commands are given, hyperfine will show a \32 comparison of the respective runtimes.")33 .required(true)34 .action(ArgAction::Append)Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 35why, one step back35 .value_hint(ValueHint::CommandString)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 36–43why, one step back36 .value_parser(NonEmptyStringValueParser::new()),37 )38 .arg(39 Arg::new("warmup")40 .long("warmup")41 .short('w')42 .value_name("NUM")43 .action(ArgAction::Set)Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
line 44why, one step back44 .value_parser(clap::value_parser!(u64))Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 45–55why, one step back45 .help(46 "Perform NUM warmup runs before the actual benchmark. This can be used \47 to fill (disk) caches for I/O-heavy programs.",48 ),49 )50 .arg(51 Arg::new("min-runs")52 .long("min-runs")53 .short('m')54 .action(ArgAction::Set)55 .value_name("NUM")Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
line 56why, one step back56 .value_parser(clap::value_parser!(u64).range(1..))Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 57–64why, one step back57 .help("Perform at least NUM runs for each command (default: 10)."),58 )59 .arg(60 Arg::new("max-runs")61 .long("max-runs")62 .short('M')63 .action(ArgAction::Set)64 .value_name("NUM")Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
line 65why, one step back65 .value_parser(clap::value_parser!(u64).range(1..))Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 66–74why, one step back66 .help("Perform at most NUM runs for each command. By default, there is no limit."),67 )68 .arg(69 Arg::new("runs")70 .long("runs")71 .conflicts_with_all(["max-runs", "min-runs"])72 .short('r')73 .action(ArgAction::Set)74 .value_name("NUM")Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
line 75why, one step back75 .value_parser(clap::value_parser!(u64).range(1..))Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 76–84why, one step back76 .help("Perform exactly NUM runs for each command. If this option is not specified, \77 hyperfine automatically determines the number of runs."),78 )79 .arg(80 Arg::new("setup")81 .long("setup")82 .short('s')83 .action(ArgAction::Set)84 .value_name("CMD")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 85why, one step back85 .value_hint(ValueHint::CommandString)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 86–93why, one step back86 .help(87 "Execute CMD before each set of timing runs. This is useful for \88 compiling your software with the provided parameters, or to do any \89 other work that should happen once before a series of benchmark runs, \90 not every time as would happen with the --prepare option."91 ),92 )93 .arg(Added option to manually specify a reference to compare the results to.Jan-Eric Nitschkebefore adoption9806ed7
lines 94–103why, one step back94 Arg::new("reference")95 .long("reference")96 .action(ArgAction::Set)97 .value_name("CMD")98 .help(99 "The reference command for the relative comparison of results. \100 If this is unset, results are compared with the fastest command as reference."101 )102 )103 .arg(Add option to name reference commandNiklas Dewallybefore adoption2166c9f
lines 104–111why, one step back104 Arg::new("reference-name")105 .long("reference-name")106 .action(ArgAction::Set)107 .value_name("CMD")108 .help("Give a meaningful name to the reference command.")109 .requires("reference")110 )111 .arg(Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 112–117why, one step back112 Arg::new("prepare")113 .long("prepare")114 .short('p')115 .action(ArgAction::Append)116 .num_args(1)117 .value_name("CMD")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 118why, one step back118 .value_hint(ValueHint::CommandString)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 119–127why, one step back119 .help(120 "Execute CMD before each timing run. This is useful for \121 clearing disk caches, for example.\nThe --prepare option can \122 be specified once for all commands or multiple times, once for \123 each command. In the latter case, each preparation command will \124 be run prior to the corresponding benchmark command.",125 ),126 )127 .arg(Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 128–144why, one step back128 Arg::new("conclude")129 .long("conclude")130 .short('C')131 .action(ArgAction::Append)132 .num_args(1)133 .value_name("CMD")134 .value_hint(ValueHint::CommandString)135 .help(136 "Execute CMD after each timing run. This is useful for killing \137 long-running processes started (e.g. a web server started in --prepare), \138 for example.\nThe --conclude option can be specified once for all \139 commands or multiple times, once for each command. In the latter case, \140 each conclude command will be run after the corresponding benchmark \141 command.",142 ),143 )144 .arg(Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 145–149why, one step back145 Arg::new("cleanup")146 .long("cleanup")147 .short('c')148 .action(ArgAction::Set)149 .value_name("CMD")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 150why, one step back150 .value_hint(ValueHint::CommandString)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 151–167why, one step back151 .help(152 "Execute CMD after the completion of all benchmarking \153 runs for each individual command to be benchmarked. \154 This is useful if the commands to be benchmarked produce \155 artifacts that need to be cleaned up."156 ),157 )158 .arg(159 Arg::new("parameter-scan")160 .long("parameter-scan")161 .short('P')162 .action(ArgAction::Set)163 .allow_hyphen_values(true)164 .value_names(["VAR", "MIN", "MAX"])165 .help(166 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \167 string '{VAR}' in each command by the current parameter value.\n\n \Clean between runs in the make parameter-scan example (#939)David Peterbefore adoptionca28ebb
line 168why, one step back168 Example: hyperfine --prepare 'make clean' -P threads 1 8 'make -j {threads}'\n\n\Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 169why, one step back169 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\Merge pull request #854 from Rohan5commit/docs/fix-arithmetic-wordingDavid Peterbefore adoption258af07
line 170why, one step back170 To have the value increase following different patterns, use shell arithmetic.\n\n \Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 171–184why, one step back171 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\172 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\173 The exact syntax may vary depending on your shell and OS."174 ),175 )176 .arg(177 Arg::new("parameter-step-size")178 .long("parameter-step-size")179 .short('D')180 .action(ArgAction::Set)181 .value_names(["DELTA"])182 .requires("parameter-scan")183 .help(184 "This argument requires --parameter-scan to be specified as well. \Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
line 185why, one step back185 Traverse the range MIN..MAX in steps of DELTA, which must be positive.\n\n \Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 186–200why, one step back186 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\187 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",188 ),189 )190 .arg(191 Arg::new("parameter-list")192 .long("parameter-list")193 .short('L')194 .action(ArgAction::Append)195 .allow_hyphen_values(true)196 .value_names(["VAR", "VALUES"])197 .conflicts_with_all(["parameter-scan", "parameter-step-size"])198 .help(199 "Perform benchmark runs for each value in the comma-separated list VALUES. \200 Replaces the string '{VAR}' in each command by the current parameter value\Use C++ compiler drivers in parameter-list examples (#936)David Peterbefore adoption1c92587
lines 201–202why, one step back201 .\n\nExample: hyperfine -L compiler g++,clang++ '{compiler} -O2 main.cpp'\n\n\202 This performs benchmarks for 'g++ -O2 main.cpp' and 'clang++ -O2 main.cpp'.\n\n\Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 203–213why, one step back203 The option can be specified multiple times to run benchmarks for all \204 possible parameter combinations.\n"205 ),206 )207 .arg(208 Arg::new("shell")209 .long("shell")210 .short('S')211 .action(ArgAction::Set)212 .value_name("SHELL")213 .overrides_with("shell")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 214why, one step back214 .value_hint(ValueHint::CommandString)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 215–232why, one step back215 .help("Set the shell to use for executing benchmarked commands. This can be the \216 name or the path to the shell executable, or a full command line \217 like \"bash --norc\". It can also be set to \"default\" to explicitly select \218 the default shell on this platform. Finally, this can also be set to \219 \"none\" to disable the shell. In this case, commands will be executed \220 directly. They can still have arguments, but more complex things like \221 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")222 )223 .arg(224 Arg::new("no-shell")225 .short('N')226 .action(ArgAction::SetTrue)227 .conflicts_with_all(["shell", "debug-mode"])228 .help("An alias for '--shell=none'.")229 )230 .arg(231 Arg::new("ignore-failure")232 .long("ignore-failure")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 233–237why, one step back233 .action(ArgAction::Set)234 .value_name("MODE")235 .num_args(0..=1)236 .default_missing_value("all-non-zero")237 .require_equals(true)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 238why, one step back238 .short('i')Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 239–241why, one step back239 .help("Ignore failures of the benchmarked programs. Without a value or with \240 'all-non-zero', all non-zero exit codes are ignored. You can also provide \241 a comma-separated list of exit codes to ignore (e.g., --ignore-failure=1,2)."),Add new --sort optionDavid Peterbefore adoptionac617c8
lines 242–273why, one step back242 )243 .arg(244 Arg::new("style")245 .long("style")246 .action(ArgAction::Set)247 .value_name("TYPE")248 .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])249 .help(250 "Set output style type (default: auto). Set this to 'basic' to disable output \251 coloring and interactive elements. Set it to 'full' to enable all effects \252 even if no interactive terminal was detected. Set this to 'nocolor' to \253 keep the interactive output without any colors. Set this to 'color' to keep \254 the colors without any interactive output. Set this to 'none' to disable all \255 the output of the tool.",256 ),257 )258 .arg(259 Arg::new("sort")260 .long("sort")261 .action(ArgAction::Set)262 .value_name("METHOD")263 .value_parser(["auto", "command", "mean-time"])264 .default_value("auto")265 .hide_default_value(true)266 .help(267 "Specify the sort order of the speed comparison summary and the exported tables for \268 markup formats (Markdown, AsciiDoc, org-mode):\n \269 * 'auto' (default): the speed comparison will be ordered by time and\n \270 the markup tables will be ordered by command (input order).\n \271 * 'command': order benchmarks in the way they were specified\n \272 * 'mean-time': order benchmarks by mean runtime\n"273 ),Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 274–280why, one step back274 )275 .arg(276 Arg::new("time-unit")277 .long("time-unit")278 .short('u')279 .action(ArgAction::Set)280 .value_name("UNIT")Merge pull request #960 from sharkdp/codex/time-unit-aliasesDavid Peterbefore adoptionfbdb75e
lines 281–289why, one step back281 .value_parser(["µs", "us", "microsecond", "microseconds", "ms", "millisecond", "milliseconds", "s", "second", "seconds", "min", "minute", "minutes", "h", "hour", "hours"])282 .help("Set the time unit to be used. If the option is not given, the time unit is determined automatically. \283 This option affects the standard output as well as all export formats except for CSV and JSON.\n\284 Possible values:\n \285 * 'µs', 'us', 'microsecond', 'microseconds'\n \286 * 'ms', 'millisecond', 'milliseconds'\n \287 * 's', 'second', 'seconds'\n \288 * 'min', 'minute', 'minutes'\n \289 * 'h', 'hour', 'hours'"),Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 290–295why, one step back290 )291 .arg(292 Arg::new("export-asciidoc")293 .long("export-asciidoc")294 .action(ArgAction::Set)295 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 296why, one step back296 .value_hint(ValueHint::FilePath)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 297–304why, one step back297 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \298 The output time unit can be changed using the --time-unit option."),299 )300 .arg(301 Arg::new("export-csv")302 .long("export-csv")303 .action(ArgAction::Set)304 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 305why, one step back305 .value_hint(ValueHint::FilePath)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 306–314why, one step back306 .help("Export the timing summary statistics as CSV to the given FILE. If you need \307 the timing results for each individual run, use the JSON export format. \308 The output time unit is always seconds."),309 )310 .arg(311 Arg::new("export-json")312 .long("export-json")313 .action(ArgAction::Set)314 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 315why, one step back315 .value_hint(ValueHint::FilePath)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 316–323why, one step back316 .help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE. \317 The output time unit is always seconds"),318 )319 .arg(320 Arg::new("export-markdown")321 .long("export-markdown")322 .action(ArgAction::Set)323 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 324why, one step back324 .value_hint(ValueHint::FilePath)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 325–332why, one step back325 .help("Export the timing summary statistics as a Markdown table to the given FILE. \326 The output time unit can be changed using the --time-unit option."),327 )328 .arg(329 Arg::new("export-orgmode")330 .long("export-orgmode")331 .action(ArgAction::Set)332 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 333why, one step back333 .value_hint(ValueHint::FilePath)Spelling and grammar fixesVille Skyttäbefore adoption178bdaa
line 334why, one step back334 .help("Export the timing summary statistics as an Emacs org-mode table to the given FILE. \Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 335–352why, one step back335 The output time unit can be changed using the --time-unit option."),336 )337 .arg(338 Arg::new("show-output")339 .long("show-output")340 .action(ArgAction::SetTrue)341 .conflicts_with("style")342 .help(343 "Print the stdout and stderr of the benchmark instead of suppressing it. \344 This will increase the time it takes for benchmarks to run, \345 so it should only be used for debugging purposes or \346 when trying to benchmark output speed.",347 ),348 )349 .arg(350 Arg::new("output")351 .long("output")352 .conflicts_with("show-output")Multiple output policiesDavid Peterbefore adoption99d24b7
line 353why, one step back353 .action(ArgAction::Append)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 354–368why, one step back354 .value_name("WHERE")355 .help(356 "Control where the output of the benchmark is redirected. Note \357 that some programs like 'grep' detect when standard output is \358 /dev/null and apply certain optimizations. To avoid that, consider \359 using '--output=pipe'.\n\360 \n\361 <WHERE> can be:\n\362 \n \363 null: Redirect output to /dev/null (the default).\n\364 \n \365 pipe: Feed the output through a pipe before discarding it.\n\366 \n \367 inherit: Don't redirect the output at all (same as '--show-output').\n\368 \n \Multiple output policiesDavid Peterbefore adoption99d24b7
lines 369–373why, one step back369 <FILE>: Write the output to the given file.\n\n\370 This option can be specified once for all commands or multiple times, once for \371 each command. Note: If you want to log the output of each and every iteration, \372 you can use a shell redirection and the '$HYPERFINE_ITERATION' environment variable:\n \373 hyperfine 'my-command > output-${HYPERFINE_ITERATION}.log'\n\n",Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 374–379why, one step back374 ),375 )376 .arg(377 Arg::new("input")378 .long("input")379 .action(ArgAction::Set)Help text wrappingDavid Peterbefore adoption2dfc919
line 380why, one step back380 .num_args(1)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 381–423why, one step back381 .value_name("WHERE")382 .help("Control where the input of the benchmark comes from.\n\383 \n\384 <WHERE> can be:\n\385 \n \386 null: Read from /dev/null (the default).\n\387 \n \388 <FILE>: Read the input from the given file."),389 )390 .arg(391 Arg::new("command-name")392 .long("command-name")393 .short('n')394 .action(ArgAction::Append)395 .num_args(1)396 .value_name("NAME")397 .help("Give a meaningful name to a command. This can be specified multiple times \398 if several commands are benchmarked."),399 )400 // This option is hidden for now, as it is not yet clear yet if we want to 'stabilize' this,401 // see discussion in https://github.com/sharkdp/hyperfine/issues/527402 .arg(403 Arg::new("min-benchmarking-time")404 .long("min-benchmarking-time")405 .action(ArgAction::Set)406 .hide(true)407 .help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \408 benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \409 `--runs` option.")410 )411 .arg(412 Arg::new("debug-mode")413 .long("debug-mode")414 .action(ArgAction::SetTrue)415 .hide(true)416 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.")417 )418}419420#[test]421fn verify_app() {422 build_command().debug_assert();423}