Skip to content
Myr

cli.rs

This file

Path

src/cli.rs

341 lines · 15.0 KiB · Rust

Last changed by

Spelling and grammar fixesVille Skyttäbefore adoption178bdaa

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)

Use max. term width, not term widthDavid Peterbefore adoptionfbe9ca6

line 24why, one step back
24 .max_term_width(80)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

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

lines 27–31why, one step back
27 .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 back
32 .required(true)

update to clap 4Benjamin Rombautbefore adoption8d38ef3

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

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 35–40why, one step back
35 )
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 back
41 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 42–50why, one step back
42 .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 back
51 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 52–58why, one step back
52 .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 back
59 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 60–65why, one step back
60 .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 back
66 .conflicts_with_all(["max-runs", "min-runs"])

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 69–76why, one step back
69 .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 back
77 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 78–89why, one step back
78 .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 back
90 .action(ArgAction::Append)

update to clap 4Benjamin Rombautbefore adoption8d38ef3

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 92–104why, one step back
92 .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 back
105 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 106–117why, one step back
106 .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 back
118 .action(ArgAction::Set)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 121–135why, one step back
121 .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 back
136 .action(ArgAction::Set)

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 138–149why, one step back
138 .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 back
150 .action(ArgAction::Append)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 154–165why, one step back
154 .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("style")165 .long("style")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

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

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

Update warning textDavid Peterbefore adoption65932dd

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

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

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

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

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

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

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

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

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

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

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

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

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393

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

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383

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

Spelling and grammar fixesVille Skyttäbefore adoption178bdaa

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

Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

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

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

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

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

Formatting of help textDavid Peterbefore adoption5db7516

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

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

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

Formatting of help textDavid Peterbefore adoption5db7516

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

Fix merge conflictsDavid Peterbefore adoption42e85f2

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

Help text wrappingDavid Peterbefore adoption2dfc919

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

Formatting of help textDavid Peterbefore adoption5db7516

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

update to clap 4Benjamin Rombautbefore adoption8d38ef3

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

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

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

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

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 336–341why, one step back
336}
337338#[test]339fn verify_app() {340 build_command().debug_assert();341}