Skip to content
Myr

cli.rs

This file

Path

src/cli.rs

340 lines · 15.0 KiB · Rust

Last changed by

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

History of this file

Take it

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 1–2why, one step back
1use std::ffi::OsString;
2

chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3

lines 3–5why, one step back
3use clap::{
4 builder::NonEmptyStringValueParser, crate_version, Arg, ArgAction, ArgMatches, Command,5};

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 6–16why, one step back
6
7pub 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 arguments

update to clap 4Benjamin Rombautbefore adoption8d38ef3

line 17why, one step back
17fn build_command() -> Command {

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 18–22why, one step back
18 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 back
23 .help_expected(true)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 24–25why, one step back
24 .arg(
25 Arg::new("command")

Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25

lines 26–30why, one step back
26 .help("The command to benchmark. This can be the name of an executable, a command \
27 line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \28 The latter is only available if the shell is not explicitly disabled via \29 '--shell=none'. If multiple commands are given, hyperfine will show a \30 comparison of the respective runtimes.")

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 31why, one step back
31 .required(true)

update to clap 4Benjamin Rombautbefore adoption8d38ef3

line 32why, one step back
32 .action(ArgAction::Append)

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

line 33why, one step back
33 .value_parser(NonEmptyStringValueParser::new()),

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 34–39why, one step back
34 )
35 .arg(36 Arg::new("warmup")37 .long("warmup")38 .short('w')39 .value_name("NUM")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 40why, one step back
40 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 41–49why, one step back
41 .help(
42 "Perform NUM warmup runs before the actual benchmark. This can be used \43 to fill (disk) caches for I/O-heavy programs.",44 ),45 )46 .arg(47 Arg::new("min-runs")48 .long("min-runs")49 .short('m')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 50why, one step back
50 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 51–57why, one step back
51 .value_name("NUM")
52 .help("Perform at least NUM runs for each command (default: 10)."),53 )54 .arg(55 Arg::new("max-runs")56 .long("max-runs")57 .short('M')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 58why, one step back
58 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 59–64why, one step back
59 .value_name("NUM")
60 .help("Perform at most NUM runs for each command. By default, there is no limit."),61 )62 .arg(63 Arg::new("runs")64 .long("runs")

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

line 65why, one step back
65 .conflicts_with_all(["max-runs", "min-runs"])

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 66why, one step back
66 .short('r')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 67why, one step back
67 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 68–75why, one step back
68 .value_name("NUM")
69 .help("Perform exactly NUM runs for each command. If this option is not specified, \70 hyperfine automatically determines the number of runs."),71 )72 .arg(73 Arg::new("setup")74 .long("setup")75 .short('s')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 76why, one step back
76 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 77–88why, one step back
77 .value_name("CMD")
78 .help(79 "Execute CMD before each set of timing runs. This is useful for \80 compiling your software with the provided parameters, or to do any \81 other work that should happen once before a series of benchmark runs, \82 not every time as would happen with the --prepare option."83 ),84 )85 .arg(86 Arg::new("prepare")87 .long("prepare")88 .short('p')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 89why, one step back
89 .action(ArgAction::Append)

update to clap 4Benjamin Rombautbefore adoption8d38ef3

line 90why, one step back
90 .num_args(1)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 91–103why, one step back
91 .value_name("CMD")
92 .help(93 "Execute CMD before each timing run. This is useful for \94 clearing disk caches, for example.\nThe --prepare option can \95 be specified once for all commands or multiple times, once for \96 each command. In the latter case, each preparation command will \97 be run prior to the corresponding benchmark command.",98 ),99 )100 .arg(101 Arg::new("cleanup")102 .long("cleanup")103 .short('c')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 104why, one step back
104 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 105–116why, one step back
105 .value_name("CMD")
106 .help(107 "Execute CMD after the completion of all benchmarking \108 runs for each individual command to be benchmarked. \109 This is useful if the commands to be benchmarked produce \110 artifacts that need to be cleaned up."111 ),112 )113 .arg(114 Arg::new("parameter-scan")115 .long("parameter-scan")116 .short('P')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 117why, one step back
117 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 118why, one step back
118 .allow_hyphen_values(true)

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

line 119why, one step back
119 .value_names(["VAR", "MIN", "MAX"])

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 120–134why, one step back
120 .help(
121 "Perform benchmark runs for each value in the range MIN..MAX. Replaces the \122 string '{VAR}' in each command by the current parameter value.\n\n \123 Example: hyperfine -P threads 1 8 'make -j {threads}'\n\n\124 This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\125 To have the value increase following different patterns, use shell arithmetics.\n\n \126 Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\127 This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\128 The exact syntax may vary depending on your shell and OS."129 ),130 )131 .arg(132 Arg::new("parameter-step-size")133 .long("parameter-step-size")134 .short('D')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 135why, one step back
135 .action(ArgAction::Set)

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

line 136why, one step back
136 .value_names(["DELTA"])

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 137–148why, one step back
137 .requires("parameter-scan")
138 .help(139 "This argument requires --parameter-scan to be specified as well. \140 Traverse the range MIN..MAX in steps of DELTA.\n\n \141 Example: hyperfine -P delay 0.3 0.7 -D 0.2 'sleep {delay}'\n\n\142 This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.",143 ),144 )145 .arg(146 Arg::new("parameter-list")147 .long("parameter-list")148 .short('L')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 149why, one step back
149 .action(ArgAction::Append)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 150why, one step back
150 .allow_hyphen_values(true)

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

lines 151–152why, one step back
151 .value_names(["VAR", "VALUES"])
152 .conflicts_with_all(["parameter-scan", "parameter-step-size"])

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 153–164why, one step back
153 .help(
154 "Perform benchmark runs for each value in the comma-separated list VALUES. \155 Replaces the string '{VAR}' in each command by the current parameter value\156 .\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\157 This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\158 The option can be specified multiple times to run benchmarks for all \159 possible parameter combinations.\n"160 ),161 )162 .arg(163 Arg::new("style")164 .long("style")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 165why, one step back
165 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 166why, one step back
166 .value_name("TYPE")

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

line 167why, one step back
167 .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 168–180why, one step back
168 .help(
169 "Set output style type (default: auto). Set this to 'basic' to disable output \170 coloring and interactive elements. Set it to 'full' to enable all effects \171 even if no interactive terminal was detected. Set this to 'nocolor' to \172 keep the interactive output without any colors. Set this to 'color' to keep \173 the colors without any interactive output. Set this to 'none' to disable all \174 the output of the tool.",175 ),176 )177 .arg(178 Arg::new("shell")179 .long("shell")180 .short('S')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 181why, one step back
181 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 182–183why, one step back
182 .value_name("SHELL")
183 .overrides_with("shell")

Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25

lines 184–186why, one step back
184 .help("Set the shell to use for executing benchmarked commands. This can be the \
185 name or the path to the shell executable, or a full command line \186 like \"bash --norc\". It can also be set to \"default\" to explicitly select \

Update warning textDavid Peterbefore adoption65932dd

line 187why, one step back
187 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 188–194why, one step back
188 \"none\" to disable the shell. In this case, commands will be executed \
189 directly. They can still have arguments, but more complex things like \190 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")191 )192 .arg(193 Arg::new("no-shell")194 .short('N')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 195why, one step back
195 .action(ArgAction::SetTrue)

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

line 196why, one step back
196 .conflicts_with_all(["shell", "debug-mode"])

Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25

line 197why, one step back
197 .help("An alias for '--shell=none'.")

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 198–201why, one step back
198 )
199 .arg(200 Arg::new("ignore-failure")201 .long("ignore-failure")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 202why, one step back
202 .action(ArgAction::SetTrue)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 203–209why, one step back
203 .short('i')
204 .help("Ignore non-zero exit codes of the benchmarked programs."),205 )206 .arg(207 Arg::new("time-unit")208 .long("time-unit")209 .short('u')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 210why, one step back
210 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 211why, one step back
211 .value_name("UNIT")

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

line 212why, one step back
212 .value_parser(["millisecond", "second"])

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

lines 213–214why, one step back
213 .help("Set the time unit to be used. Possible values: millisecond, second. \
214 If the option is not given, the time unit is determined automatically. \

Make --time-unit help text more generic.Engineer-of-Efficiencybefore adoptionedb29f4

line 215why, one step back
215 This option affects the standard output as well as all export formats except for CSV and JSON."),

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 216–219why, one step back
216 )
217 .arg(218 Arg::new("export-asciidoc")219 .long("export-asciidoc")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 220why, one step back
220 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 221why, one step back
221 .value_name("FILE")

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

line 222why, one step back
222 .help("Export the timing summary statistics as an AsciiDoc table to the given FILE. \

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

line 223why, one step back
223 The output time unit can be changed using the --time-unit option."),

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 224–227why, one step back
224 )
225 .arg(226 Arg::new("export-csv")227 .long("export-csv")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 228why, one step back
228 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 229–230why, one step back
229 .value_name("FILE")
230 .help("Export the timing summary statistics as CSV to the given FILE. If you need \

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

line 231why, one step back
231 the timing results for each individual run, use the JSON export format. \

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

line 232why, one step back
232 The output time unit is always seconds."),

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 233–236why, one step back
233 )
234 .arg(235 Arg::new("export-json")236 .long("export-json")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 237why, one step back
237 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 238why, one step back
238 .value_name("FILE")

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

line 239why, one step back
239 .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 240why, one step back
240 The output time unit is always seconds"),

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 241–244why, one step back
241 )
242 .arg(243 Arg::new("export-markdown")244 .long("export-markdown")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 245why, one step back
245 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 246why, one step back
246 .value_name("FILE")

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

line 247why, one step back
247 .help("Export the timing summary statistics as a Markdown table to the given FILE. \

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

line 248why, one step back
248 The output time unit can be changed using the --time-unit option."),

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 249–250why, one step back
249 )
250 .arg(

Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383

lines 251–252why, one step back
251 Arg::new("export-orgmode")
252 .long("export-orgmode")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 253why, one step back
253 .action(ArgAction::Set)

Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383

line 254why, one step back
254 .value_name("FILE")

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

line 255why, one step back
255 .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 256why, one step back
256 The output time unit can be changed using the --time-unit option."),

Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383

lines 257–258why, one step back
257 )
258 .arg(

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 259–260why, one step back
259 Arg::new("show-output")
260 .long("show-output")

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

line 261why, one step back
261 .action(ArgAction::SetTrue)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 262–270why, one step back
262 .conflicts_with("style")
263 .help(264 "Print the stdout and stderr of the benchmark instead of suppressing it. \265 This will increase the time it takes for benchmarks to run, \266 so it should only be used for debugging purposes or \267 when trying to benchmark output speed.",268 ),269 )270 .arg(

Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c

lines 271–273why, one step back
271 Arg::new("output")
272 .long("output")273 .conflicts_with("show-output")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 274why, one step back
274 .action(ArgAction::Set)

Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c

lines 275–276why, one step back
275 .value_name("WHERE")
276 .help(

Formatting of help textDavid Peterbefore adoption5db7516

lines 277–290why, one step back
277 "Control where the output of the benchmark is redirected. Note \
278 that some programs like 'grep' detect when standard output is \279 /dev/null and apply certain optimizations. To avoid that, consider \280 using '--output=pipe'.\n\281 \n\282 <WHERE> can be:\n\283 \n \284 null: Redirect output to /dev/null (the default).\n\285 \n \286 pipe: Feed the output through a pipe before discarding it.\n\287 \n \288 inherit: Don't redirect the output at all (same as '--show-output').\n\289 \n \290 <FILE>: Write the output to the given file.",

Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c

lines 291–293why, one step back
291 ),
292 )293 .arg(

Formatting of help textDavid Peterbefore adoption5db7516

lines 294–295why, one step back
294 Arg::new("input")
295 .long("input")

Fix merge conflictsDavid Peterbefore adoption42e85f2

line 296why, one step back
296 .action(ArgAction::Set)

Formatting of help textDavid Peterbefore adoption5db7516

lines 297–307why, one step back
297 .number_of_values(1)
298 .value_name("WHERE")299 .help("Control where the input of the benchmark comes from.\n\300 \n\301 <WHERE> can be:\n\302 \n \303 null: Read from /dev/null (the default).\n\304 \n \305 <FILE>: Read the input from the given file."),306 )307 .arg(

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 308–310why, one step back
308 Arg::new("command-name")
309 .long("command-name")310 .short('n')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 311why, one step back
311 .action(ArgAction::Append)

update to clap 4Benjamin Rombautbefore adoption8d38ef3

line 312why, one step back
312 .num_args(1)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 313–316why, one step back
313 .value_name("NAME")
314 .help("Give a meaningful name to a command. This can be specified multiple times \315 if several commands are benchmarked."),316 )

Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3

lines 317–321why, one step back
317 // This option is hidden for now, as it is not yet clear yet if we want to 'stabilize' this,
318 // see discussion in https://github.com/sharkdp/hyperfine/issues/527319 .arg(320 Arg::new("min-benchmarking-time")321 .long("min-benchmarking-time")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 322why, one step back
322 .action(ArgAction::Set)

Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3

lines 323–327why, one step back
323 .hide(true)
324 .help("Set the minimum time (in seconds) to run benchmarks. Note that the number of \325 benchmark runs is additionally influenced by the `--min-runs`, `--max-runs`, and \326 `--runs` option.")327 )

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 328–330why, one step back
328 .arg(
329 Arg::new("debug-mode")330 .long("debug-mode")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

line 331why, one step back
331 .action(ArgAction::SetTrue)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 332why, one step back
332 .hide(true)

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

line 333why, one step back
333 .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 334why, one step back
334 )

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 335–340why, one step back
335}
336337#[test]338fn verify_app() {339 build_command().debug_assert();340}