cli.rs
This file
Path
src/cli.rs
408 lines · 18.2 KiB · Rust
Last changed by
Add option to name reference commandNiklas Dewallybefore adoption2166c9f
History of this fileTake it
The walk stopped after 200 commits: lines older than 779d425 point at it.
Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 1–2why, one step back1use std::ffi::OsString;2chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 3–4why, one step back3use clap::{4 builder::NonEmptyStringValueParser, crate_version, Arg, ArgAction, ArgMatches, Command,Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 5why, one step back5 ValueHint,chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
line 6why, one step back6};Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 7–17why, one step back78pub 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 argumentsupdate to clap 4Benjamin Rombautbefore adoption8d38ef3
line 18why, one step back18fn build_command() -> Command {Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 19–23why, one step back19 Command::new("hyperfine")20 .version(crate_version!())21 .next_line_help(true)22 .hide_possible_values(true)23 .about("A command-line benchmarking tool.")use wrap_helpBenjamin Rombautbefore adoption17aca87
line 24why, one step back24 .help_expected(true)Use max. term width, not term widthDavid Peterbefore adoptionfbe9ca6
line 25why, one step back25 .max_term_width(80)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 26–33why, 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)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 34why, one step back34 .action(ArgAction::Append)Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 35why, one step back35 .value_hint(ValueHint::CommandString)add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 36why, one step back36 .value_parser(NonEmptyStringValueParser::new()),Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 37–42why, one step back37 )38 .arg(39 Arg::new("warmup")40 .long("warmup")41 .short('w')42 .value_name("NUM")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 43why, one step back43 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 44–52why, one step back44 .help(45 "Perform NUM warmup runs before the actual benchmark. This can be used \46 to fill (disk) caches for I/O-heavy programs.",47 ),48 )49 .arg(50 Arg::new("min-runs")51 .long("min-runs")52 .short('m')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 53why, one step back53 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 54–60why, one step back54 .value_name("NUM")55 .help("Perform at least NUM runs for each command (default: 10)."),56 )57 .arg(58 Arg::new("max-runs")59 .long("max-runs")60 .short('M')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 61why, one step back61 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 62–67why, one step back62 .value_name("NUM")63 .help("Perform at most NUM runs for each command. By default, there is no limit."),64 )65 .arg(66 Arg::new("runs")67 .long("runs")Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 68why, one step back68 .conflicts_with_all(["max-runs", "min-runs"])Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 69why, one step back69 .short('r')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 70why, one step back70 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 71–78why, one step back71 .value_name("NUM")72 .help("Perform exactly NUM runs for each command. If this option is not specified, \73 hyperfine automatically determines the number of runs."),74 )75 .arg(76 Arg::new("setup")77 .long("setup")78 .short('s')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 79why, one step back79 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 80why, one step back80 .value_name("CMD")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 81why, one step back81 .value_hint(ValueHint::CommandString)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 82–89why, one step back82 .help(83 "Execute CMD before each set of timing runs. This is useful for \84 compiling your software with the provided parameters, or to do any \85 other work that should happen once before a series of benchmark runs, \86 not every time as would happen with the --prepare option."87 ),88 )89 .arg(Added option to manually specify a reference to compare the results to.Jan-Eric Nitschkebefore adoption9806ed7
lines 90–99why, one step back90 Arg::new("reference")91 .long("reference")92 .action(ArgAction::Set)93 .value_name("CMD")94 .help(95 "The reference command for the relative comparison of results. \96 If this is unset, results are compared with the fastest command as reference."97 )98 )99 .arg(Add option to name reference commandNiklas Dewallybefore adoption2166c9f
lines 100–107why, one step back100 Arg::new("reference-name")101 .long("reference-name")102 .action(ArgAction::Set)103 .value_name("CMD")104 .help("Give a meaningful name to the reference command.")105 .requires("reference")106 )107 .arg(Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 108–110why, one step back108 Arg::new("prepare")109 .long("prepare")110 .short('p')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 111why, one step back111 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 112why, one step back112 .num_args(1)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 113why, one step back113 .value_name("CMD")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 114why, one step back114 .value_hint(ValueHint::CommandString)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 115–123why, one step back115 .help(116 "Execute CMD before each timing run. This is useful for \117 clearing disk caches, for example.\nThe --prepare option can \118 be specified once for all commands or multiple times, once for \119 each command. In the latter case, each preparation command will \120 be run prior to the corresponding benchmark command.",121 ),122 )123 .arg(Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 124–140why, one step back124 Arg::new("conclude")125 .long("conclude")126 .short('C')127 .action(ArgAction::Append)128 .num_args(1)129 .value_name("CMD")130 .value_hint(ValueHint::CommandString)131 .help(132 "Execute CMD after each timing run. This is useful for killing \133 long-running processes started (e.g. a web server started in --prepare), \134 for example.\nThe --conclude option can be specified once for all \135 commands or multiple times, once for each command. In the latter case, \136 each conclude command will be run after the corresponding benchmark \137 command.",138 ),139 )140 .arg(Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 141–143why, one step back141 Arg::new("cleanup")142 .long("cleanup")143 .short('c')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 144why, one step back144 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 145why, one step back145 .value_name("CMD")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 146why, one step back146 .value_hint(ValueHint::CommandString)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 147–157why, one step back147 .help(148 "Execute CMD after the completion of all benchmarking \149 runs for each individual command to be benchmarked. \150 This is useful if the commands to be benchmarked produce \151 artifacts that need to be cleaned up."152 ),153 )154 .arg(155 Arg::new("parameter-scan")156 .long("parameter-scan")157 .short('P')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 158why, one step back158 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 159why, one step back159 .allow_hyphen_values(true)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 160why, one step back160 .value_names(["VAR", "MIN", "MAX"])Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 161–175why, one step back161 .help(162 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \163 string '{VAR}' in each command by the current parameter value.\n\n \164 Example: hyperfine -P threads 1 8 'make -j {threads}'\n\n\165 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\166 To have the value increase following different patterns, use shell arithmetics.\n\n \167 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\168 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\169 The exact syntax may vary depending on your shell and OS."170 ),171 )172 .arg(173 Arg::new("parameter-step-size")174 .long("parameter-step-size")175 .short('D')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 176why, one step back176 .action(ArgAction::Set)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 177why, one step back177 .value_names(["DELTA"])Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 178–189why, one step back178 .requires("parameter-scan")179 .help(180 "This argument requires --parameter-scan to be specified as well. \181 Traverse the range MIN..MAX in steps of DELTA.\n\n \182 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\183 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",184 ),185 )186 .arg(187 Arg::new("parameter-list")188 .long("parameter-list")189 .short('L')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 190why, one step back190 .action(ArgAction::Append)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 191why, one step back191 .allow_hyphen_values(true)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 192–193why, one step back192 .value_names(["VAR", "VALUES"])193 .conflicts_with_all(["parameter-scan", "parameter-step-size"])Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 194–206why, one step back194 .help(195 "Perform benchmark runs for each value in the comma-separated list VALUES. \196 Replaces the string '{VAR}' in each command by the current parameter value\197 .\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\198 This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\199 The option can be specified multiple times to run benchmarks for all \200 possible parameter combinations.\n"201 ),202 )203 .arg(204 Arg::new("shell")205 .long("shell")206 .short('S')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 207why, one step back207 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 208–209why, one step back208 .value_name("SHELL")209 .overrides_with("shell")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 210why, one step back210 .value_hint(ValueHint::CommandString)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 211–221why, one step back211 .help("Set the shell to use for executing benchmarked commands. This can be the \212 name or the path to the shell executable, or a full command line \213 like \"bash --norc\". It can also be set to \"default\" to explicitly select \214 the default shell on this platform. Finally, this can also be set to \215 \"none\" to disable the shell. In this case, commands will be executed \216 directly. They can still have arguments, but more complex things like \217 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")218 )219 .arg(220 Arg::new("no-shell")221 .short('N')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 222why, one step back222 .action(ArgAction::SetTrue)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 223why, one step back223 .conflicts_with_all(["shell", "debug-mode"])Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 224–228why, one step back224 .help("An alias for '--shell=none'.")225 )226 .arg(227 Arg::new("ignore-failure")228 .long("ignore-failure")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 229why, one step back229 .action(ArgAction::SetTrue)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 230–231why, one step back230 .short('i')231 .help("Ignore non-zero exit codes of the benchmarked programs."),Add new --sort optionDavid Peterbefore adoptionac617c8
lines 232–263why, one step back232 )233 .arg(234 Arg::new("style")235 .long("style")236 .action(ArgAction::Set)237 .value_name("TYPE")238 .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])239 .help(240 "Set output style type (default: auto). Set this to 'basic' to disable output \241 coloring and interactive elements. Set it to 'full' to enable all effects \242 even if no interactive terminal was detected. Set this to 'nocolor' to \243 keep the interactive output without any colors. Set this to 'color' to keep \244 the colors without any interactive output. Set this to 'none' to disable all \245 the output of the tool.",246 ),247 )248 .arg(249 Arg::new("sort")250 .long("sort")251 .action(ArgAction::Set)252 .value_name("METHOD")253 .value_parser(["auto", "command", "mean-time"])254 .default_value("auto")255 .hide_default_value(true)256 .help(257 "Specify the sort order of the speed comparison summary and the exported tables for \258 markup formats (Markdown, AsciiDoc, org-mode):\n \259 * 'auto' (default): the speed comparison will be ordered by time and\n \260 the markup tables will be ordered by command (input order).\n \261 * 'command': order benchmarks in the way they were specified\n \262 * 'mean-time': order benchmarks by mean runtime\n"263 ),Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 264–268why, one step back264 )265 .arg(266 Arg::new("time-unit")267 .long("time-unit")268 .short('u')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 269why, one step back269 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 270why, one step back270 .value_name("UNIT")Add support for microseconds, closes #684David Peterbefore adoption4564977
lines 271–272why, one step back271 .value_parser(["microsecond", "millisecond", "second"])272 .help("Set the time unit to be used. Possible values: microsecond, millisecond, second. \Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 273–278why, one step back273 If the option is not given, the time unit is determined automatically. \274 This option affects the standard output as well as all export formats except for CSV and JSON."),275 )276 .arg(277 Arg::new("export-asciidoc")278 .long("export-asciidoc")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 279why, one step back279 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 280why, one step back280 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 281why, one step back281 .value_hint(ValueHint::FilePath)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 282–287why, one step back282 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \283 The output time unit can be changed using the --time-unit option."),284 )285 .arg(286 Arg::new("export-csv")287 .long("export-csv")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 288why, one step back288 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 289why, one step back289 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 290why, one step back290 .value_hint(ValueHint::FilePath)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 291–297why, one step back291 .help("Export the timing summary statistics as CSV to the given FILE. If you need \292 the timing results for each individual run, use the JSON export format. \293 The output time unit is always seconds."),294 )295 .arg(296 Arg::new("export-json")297 .long("export-json")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 298why, one step back298 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 299why, one step back299 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 300why, one step back300 .value_hint(ValueHint::FilePath)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 301–306why, one step back301 .help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE. \302 The output time unit is always seconds"),303 )304 .arg(305 Arg::new("export-markdown")306 .long("export-markdown")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 307why, one step back307 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 308why, one step back308 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 309why, one step back309 .value_hint(ValueHint::FilePath)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 310–315why, one step back310 .help("Export the timing summary statistics as a Markdown table to the given FILE. \311 The output time unit can be changed using the --time-unit option."),312 )313 .arg(314 Arg::new("export-orgmode")315 .long("export-orgmode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 316why, one step back316 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
line 317why, one step back317 .value_name("FILE")Specify clap::ValueHint for argumentsAlbert Safinbefore adoption4ffe96b
line 318why, one step back318 .value_hint(ValueHint::FilePath)Spelling and grammar fixesVille Skyttäbefore adoption178bdaa
line 319why, one step back319 .help("Export the timing summary statistics as an Emacs org-mode table to the given FILE. \Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 320–324why, one step back320 The output time unit can be changed using the --time-unit option."),321 )322 .arg(323 Arg::new("show-output")324 .long("show-output")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 325why, one step back325 .action(ArgAction::SetTrue)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 326–337why, one step back326 .conflicts_with("style")327 .help(328 "Print the stdout and stderr of the benchmark instead of suppressing it. \329 This will increase the time it takes for benchmarks to run, \330 so it should only be used for debugging purposes or \331 when trying to benchmark output speed.",332 ),333 )334 .arg(335 Arg::new("output")336 .long("output")337 .conflicts_with("show-output")Multiple output policiesDavid Peterbefore adoption99d24b7
line 338why, one step back338 .action(ArgAction::Append)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 339–340why, one step back339 .value_name("WHERE")340 .help(Formatting of help textDavid Peterbefore adoption5db7516
lines 341–353why, one step back341 "Control where the output of the benchmark is redirected. Note \342 that some programs like 'grep' detect when standard output is \343 /dev/null and apply certain optimizations. To avoid that, consider \344 using '--output=pipe'.\n\345 \n\346 <WHERE> can be:\n\347 \n \348 null: Redirect output to /dev/null (the default).\n\349 \n \350 pipe: Feed the output through a pipe before discarding it.\n\351 \n \352 inherit: Don't redirect the output at all (same as '--show-output').\n\353 \n \Multiple output policiesDavid Peterbefore adoption99d24b7
lines 354–358why, one step back354 <FILE>: Write the output to the given file.\n\n\355 This option can be specified once for all commands or multiple times, once for \356 each command. Note: If you want to log the output of each and every iteration, \357 you can use a shell redirection and the '$HYPERFINE_ITERATION' environment variable:\n \358 hyperfine 'my-command > output-${HYPERFINE_ITERATION}.log'\n\n",Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 359–361why, one step back359 ),360 )361 .arg(Formatting of help textDavid Peterbefore adoption5db7516
lines 362–363why, one step back362 Arg::new("input")363 .long("input")Fix merge conflictsDavid Peterbefore adoption42e85f2
line 364why, one step back364 .action(ArgAction::Set)Help text wrappingDavid Peterbefore adoption2dfc919
line 365why, one step back365 .num_args(1)Formatting of help textDavid Peterbefore adoption5db7516
lines 366–375why, one step back366 .value_name("WHERE")367 .help("Control where the input of the benchmark comes from.\n\368 \n\369 <WHERE> can be:\n\370 \n \371 null: Read from /dev/null (the default).\n\372 \n \373 <FILE>: Read the input from the given file."),374 )375 .arg(Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 376–378why, one step back376 Arg::new("command-name")377 .long("command-name")378 .short('n')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 379why, one step back379 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 380why, one step back380 .num_args(1)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 381–389why, one step back381 .value_name("NAME")382 .help("Give a meaningful name to a command. This can be specified multiple times \383 if several commands are benchmarked."),384 )385 // This option is hidden for now, as it is not yet clear yet if we want to 'stabilize' this,386 // see discussion in https://github.com/sharkdp/hyperfine/issues/527387 .arg(388 Arg::new("min-benchmarking-time")389 .long("min-benchmarking-time")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 390why, one step back390 .action(ArgAction::Set)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 391–398why, one step back391 .hide(true)392 .help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \393 benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \394 `--runs` option.")395 )396 .arg(397 Arg::new("debug-mode")398 .long("debug-mode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 399why, one step back399 .action(ArgAction::SetTrue)Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 400–401why, one step back400 .hide(true)401 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.")Added --stdin-data argumentSteve Neasebefore adoptione38acdb
line 402why, one step back402 )Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 403–408why, one step back403}404405#[test]406fn verify_app() {407 build_command().debug_assert();408}