cli.rs
This file
Path
src/cli.rs
358 lines · 15.8 KiB · Rust
Last changed by
Add new --sort optionDavid Peterbefore adoptionac617c8
History of this fileTake it
Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 1–2why, one step back1use std::ffi::OsString;2chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 3–5why, one step back3use clap::{4 builder::NonEmptyStringValueParser, crate_version, Arg, ArgAction, ArgMatches, Command,5};Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 6–16why, one step back67pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches8where9 I: IntoIterator<Item = T>,10 T: Into<OsString> + Clone + 'a,11{12 let command = build_command();13 command.get_matches_from(args)14}1516/// Build the clap command for parsing command line argumentsupdate to clap 4Benjamin Rombautbefore adoption8d38ef3
line 17why, one step back17fn build_command() -> Command {Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 18–22why, one step back18 Command::new("hyperfine")19 .version(crate_version!())20 .next_line_help(true)21 .hide_possible_values(true)22 .about("A command-line benchmarking tool.")use wrap_helpBenjamin Rombautbefore adoption17aca87
line 23why, one step back23 .help_expected(true)Use max. term width, not term widthDavid Peterbefore adoptionfbe9ca6
line 24why, one step back24 .max_term_width(80)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 25–26why, one step back25 .arg(26 Arg::new("command")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 27–31why, one step back27 .help("The command to benchmark. This can be the name of an executable, a command \28 line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \29 The latter is only available if the shell is not explicitly disabled via \30 '--shell=none'. If multiple commands are given, hyperfine will show a \31 comparison of the respective runtimes.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 32why, one step back32 .required(true)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 33why, one step back33 .action(ArgAction::Append)add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 34why, one step back34 .value_parser(NonEmptyStringValueParser::new()),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 35–40why, one step back35 )36 .arg(37 Arg::new("warmup")38 .long("warmup")39 .short('w')40 .value_name("NUM")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 41why, one step back41 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 42–50why, one step back42 .help(43 "Perform NUM warmup runs before the actual benchmark. This can be used \44 to fill (disk) caches for I/O-heavy programs.",45 ),46 )47 .arg(48 Arg::new("min-runs")49 .long("min-runs")50 .short('m')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 51why, one step back51 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 52–58why, one step back52 .value_name("NUM")53 .help("Perform at least NUM runs for each command (default: 10)."),54 )55 .arg(56 Arg::new("max-runs")57 .long("max-runs")58 .short('M')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 59why, one step back59 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 60–65why, one step back60 .value_name("NUM")61 .help("Perform at most NUM runs for each command. By default, there is no limit."),62 )63 .arg(64 Arg::new("runs")65 .long("runs")Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 66why, one step back66 .conflicts_with_all(["max-runs", "min-runs"])Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 67why, one step back67 .short('r')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 68why, one step back68 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 69–76why, one step back69 .value_name("NUM")70 .help("Perform exactly NUM runs for each command. If this option is not specified, \71 hyperfine automatically determines the number of runs."),72 )73 .arg(74 Arg::new("setup")75 .long("setup")76 .short('s')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 77why, one step back77 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 78–89why, one step back78 .value_name("CMD")79 .help(80 "Execute CMD before each set of timing runs. This is useful for \81 compiling your software with the provided parameters, or to do any \82 other work that should happen once before a series of benchmark runs, \83 not every time as would happen with the --prepare option."84 ),85 )86 .arg(87 Arg::new("prepare")88 .long("prepare")89 .short('p')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 90why, one step back90 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 91why, one step back91 .num_args(1)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 92–104why, one step back92 .value_name("CMD")93 .help(94 "Execute CMD before each timing run. This is useful for \95 clearing disk caches, for example.\nThe --prepare option can \96 be specified once for all commands or multiple times, once for \97 each command. In the latter case, each preparation command will \98 be run prior to the corresponding benchmark command.",99 ),100 )101 .arg(102 Arg::new("cleanup")103 .long("cleanup")104 .short('c')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 105why, one step back105 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 106–117why, one step back106 .value_name("CMD")107 .help(108 "Execute CMD after the completion of all benchmarking \109 runs for each individual command to be benchmarked. \110 This is useful if the commands to be benchmarked produce \111 artifacts that need to be cleaned up."112 ),113 )114 .arg(115 Arg::new("parameter-scan")116 .long("parameter-scan")117 .short('P')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 118why, one step back118 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 119why, one step back119 .allow_hyphen_values(true)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 120why, one step back120 .value_names(["VAR", "MIN", "MAX"])Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 121–135why, one step back121 .help(122 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \123 string '{VAR}' in each command by the current parameter value.\n\n \124 Example: hyperfine -P threads 1 8 'make -j {threads}'\n\n\125 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\126 To have the value increase following different patterns, use shell arithmetics.\n\n \127 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\128 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\129 The exact syntax may vary depending on your shell and OS."130 ),131 )132 .arg(133 Arg::new("parameter-step-size")134 .long("parameter-step-size")135 .short('D')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 136why, one step back136 .action(ArgAction::Set)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 137why, one step back137 .value_names(["DELTA"])Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 138–149why, one step back138 .requires("parameter-scan")139 .help(140 "This argument requires --parameter-scan to be specified as well. \141 Traverse the range MIN..MAX in steps of DELTA.\n\n \142 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\143 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",144 ),145 )146 .arg(147 Arg::new("parameter-list")148 .long("parameter-list")149 .short('L')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 150why, one step back150 .action(ArgAction::Append)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 151why, one step back151 .allow_hyphen_values(true)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 152–153why, one step back152 .value_names(["VAR", "VALUES"])153 .conflicts_with_all(["parameter-scan", "parameter-step-size"])Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 154–166why, one step back154 .help(155 "Perform benchmark runs for each value in the comma-separated list VALUES. \156 Replaces the string '{VAR}' in each command by the current parameter value\157 .\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\158 This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\159 The option can be specified multiple times to run benchmarks for all \160 possible parameter combinations.\n"161 ),162 )163 .arg(164 Arg::new("shell")165 .long("shell")166 .short('S')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 167why, one step back167 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 168–169why, one step back168 .value_name("SHELL")169 .overrides_with("shell")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 170–172why, one step back170 .help("Set the shell to use for executing benchmarked commands. This can be the \171 name or the path to the shell executable, or a full command line \172 like \"bash --norc\". It can also be set to \"default\" to explicitly select \Update warning textDavid Peterbefore adoption65932dd
line 173why, one step back173 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 174–180why, one step back174 \"none\" to disable the shell. In this case, commands will be executed \175 directly. They can still have arguments, but more complex things like \176 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")177 )178 .arg(179 Arg::new("no-shell")180 .short('N')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 181why, one step back181 .action(ArgAction::SetTrue)Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 182why, one step back182 .conflicts_with_all(["shell", "debug-mode"])Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
line 183why, one step back183 .help("An alias for '--shell=none'.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 184–187why, one step back184 )185 .arg(186 Arg::new("ignore-failure")187 .long("ignore-failure")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 188why, one step back188 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 189–190why, one step back189 .short('i')190 .help("Ignore non-zero exit codes of the benchmarked programs."),Add new --sort optionDavid Peterbefore adoptionac617c8
lines 191–222why, one step back191 )192 .arg(193 Arg::new("style")194 .long("style")195 .action(ArgAction::Set)196 .value_name("TYPE")197 .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])198 .help(199 "Set output style type (default: auto). Set this to 'basic' to disable output \200 coloring and interactive elements. Set it to 'full' to enable all effects \201 even if no interactive terminal was detected. Set this to 'nocolor' to \202 keep the interactive output without any colors. Set this to 'color' to keep \203 the colors without any interactive output. Set this to 'none' to disable all \204 the output of the tool.",205 ),206 )207 .arg(208 Arg::new("sort")209 .long("sort")210 .action(ArgAction::Set)211 .value_name("METHOD")212 .value_parser(["auto", "command", "mean-time"])213 .default_value("auto")214 .hide_default_value(true)215 .help(216 "Specify the sort order of the speed comparison summary and the exported tables for \217 markup formats (Markdown, AsciiDoc, org-mode):\n \218 * 'auto' (default): the speed comparison will be ordered by time and\n \219 the markup tables will be ordered by command (input order).\n \220 * 'command': order benchmarks in the way they were specified\n \221 * 'mean-time': order benchmarks by mean runtime\n"222 ),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 223–227why, one step back223 )224 .arg(225 Arg::new("time-unit")226 .long("time-unit")227 .short('u')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 228why, one step back228 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 229why, one step back229 .value_name("UNIT")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 230why, one step back230 .value_parser(["millisecond", "second"])Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
lines 231–232why, one step back231 .help("Set the time unit to be used. Possible values: millisecond, second. \232 If the option is not given, the time unit is determined automatically. \Make --time-unit help text more generic.Engineer-of-Efficiencybefore adoptionedb29f4
line 233why, one step back233 This option affects the standard output as well as all export formats except for CSV and JSON."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 234–237why, one step back234 )235 .arg(236 Arg::new("export-asciidoc")237 .long("export-asciidoc")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 238why, one step back238 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 239why, one step back239 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 240why, one step back240 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 241why, one step back241 The output time unit can be changed using the --time-unit option."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 242–245why, one step back242 )243 .arg(244 Arg::new("export-csv")245 .long("export-csv")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 246why, one step back246 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 247–248why, one step back247 .value_name("FILE")248 .help("Export the timing summary statistics as CSV to the given FILE. If you need \Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 249why, one step back249 the timing results for each individual run, use the JSON export format. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 250why, one step back250 The output time unit is always seconds."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 251–254why, one step back251 )252 .arg(253 Arg::new("export-json")254 .long("export-json")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 255why, one step back255 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 256why, one step back256 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 257why, one step back257 .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 258why, one step back258 The output time unit is always seconds"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 259–262why, one step back259 )260 .arg(261 Arg::new("export-markdown")262 .long("export-markdown")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 263why, one step back263 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 264why, one step back264 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 265why, one step back265 .help("Export the timing summary statistics as a Markdown table to the given FILE. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 266why, one step back266 The output time unit can be changed using the --time-unit option."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 267–268why, one step back267 )268 .arg(Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 269–270why, one step back269 Arg::new("export-orgmode")270 .long("export-orgmode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 271why, one step back271 .action(ArgAction::Set)Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 272why, one step back272 .value_name("FILE")Spelling and grammar fixesVille Skyttäbefore adoption178bdaa
line 273why, one step back273 .help("Export the timing summary statistics as an Emacs org-mode table to the given FILE. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 274why, one step back274 The output time unit can be changed using the --time-unit option."),Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 275–276why, one step back275 )276 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 277–278why, one step back277 Arg::new("show-output")278 .long("show-output")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 279why, one step back279 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 280–288why, one step back280 .conflicts_with("style")281 .help(282 "Print the stdout and stderr of the benchmark instead of suppressing it. \283 This will increase the time it takes for benchmarks to run, \284 so it should only be used for debugging purposes or \285 when trying to benchmark output speed.",286 ),287 )288 .arg(Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 289–291why, one step back289 Arg::new("output")290 .long("output")291 .conflicts_with("show-output")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 292why, one step back292 .action(ArgAction::Set)Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 293–294why, one step back293 .value_name("WHERE")294 .help(Formatting of help textDavid Peterbefore adoption5db7516
lines 295–308why, one step back295 "Control where the output of the benchmark is redirected. Note \296 that some programs like 'grep' detect when standard output is \297 /dev/null and apply certain optimizations. To avoid that, consider \298 using '--output=pipe'.\n\299 \n\300 <WHERE> can be:\n\301 \n \302 null: Redirect output to /dev/null (the default).\n\303 \n \304 pipe: Feed the output through a pipe before discarding it.\n\305 \n \306 inherit: Don't redirect the output at all (same as '--show-output').\n\307 \n \308 <FILE>: Write the output to the given file.",Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 309–311why, one step back309 ),310 )311 .arg(Formatting of help textDavid Peterbefore adoption5db7516
lines 312–313why, one step back312 Arg::new("input")313 .long("input")Fix merge conflictsDavid Peterbefore adoption42e85f2
line 314why, one step back314 .action(ArgAction::Set)Help text wrappingDavid Peterbefore adoption2dfc919
line 315why, one step back315 .num_args(1)Formatting of help textDavid Peterbefore adoption5db7516
lines 316–325why, one step back316 .value_name("WHERE")317 .help("Control where the input of the benchmark comes from.\n\318 \n\319 <WHERE> can be:\n\320 \n \321 null: Read from /dev/null (the default).\n\322 \n \323 <FILE>: Read the input from the given file."),324 )325 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 326–328why, one step back326 Arg::new("command-name")327 .long("command-name")328 .short('n')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 329why, one step back329 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 330why, one step back330 .num_args(1)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 331–334why, one step back331 .value_name("NAME")332 .help("Give a meaningful name to a command. This can be specified multiple times \333 if several commands are benchmarked."),334 )Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3
lines 335–339why, one step back335 // This option is hidden for now, as it is not yet clear yet if we want to 'stabilize' this,336 // see discussion in https://github.com/sharkdp/hyperfine/issues/527337 .arg(338 Arg::new("min-benchmarking-time")339 .long("min-benchmarking-time")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 340why, one step back340 .action(ArgAction::Set)Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3
lines 341–345why, one step back341 .hide(true)342 .help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \343 benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \344 `--runs` option.")345 )Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 346–348why, one step back346 .arg(347 Arg::new("debug-mode")348 .long("debug-mode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 349why, one step back349 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 350why, one step back350 .hide(true)Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 351why, one step back351 .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 352why, one step back352 )Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 353–358why, one step back353}354355#[test]356fn verify_app() {357 build_command().debug_assert();358}