Skip to content
Myr

cli.rs

This file

Path

src/cli.rs

320 lines · 14.3 KiB · Rust

Last changed by

chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3

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–66why, 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")65 .conflicts_with_all(&["max-runs", "min-runs"])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

lines 118–134why, one step back
118 .allow_hyphen_values(true)
119 .value_names(&["VAR", "MIN", "MAX"])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)

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 136–148why, one step back
136 .value_names(&["DELTA"])
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

lines 150–164why, one step back
150 .allow_hyphen_values(true)
151 .value_names(&["VAR", "VALUES"])152 .conflicts_with_all(&["parameter-scan", "parameter-step-size"])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)

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

lines 196–197why, one step back
196 .conflicts_with_all(&["shell", "debug-mode"])
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(

Clarify --output's help textTavian Barnesbefore adoptiondfd1046

lines 277–282why, one step back
277 "Control where the output of the benchmark is redirected. <WHERE> can be:\n\n\
278 null: Redirect output to /dev/null (the default). \279 Note that some programs like 'grep' detect when standard output is /dev/null \280 and apply certain optimizations. To avoid that, consider using \281 '--output=pipe'.\n\n\282 pipe: Feed the output through a pipe before discarding it.\n\n\

Add --output=inherit as an alias for --show-outputTavian Barnesbefore adoptionecee9df

line 283why, one step back
283 inherit: Don't redirect the output at all (same as '--show-output').\n\n\

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

lines 284–287why, one step back
284 <FILE>: Write the output to the given file.",
285 ),286 )287 .arg(

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 288–290why, one step back
288 Arg::new("command-name")
289 .long("command-name")290 .short('n')

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

update to clap 4Benjamin Rombautbefore adoption8d38ef3

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

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

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

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

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

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 308–310why, one step back
308 .arg(
309 Arg::new("debug-mode")310 .long("debug-mode")

use set and settrueBenjamin Rombautbefore adoption27ec9e2

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

Update dependenciesDavid Peterbefore adoptionf2f1dd9

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

Add full stop after help messagesDavid Peterbefore adoptionde0ace4

line 313why, one step back
313 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.")

Update dependenciesDavid Peterbefore adoptionf2f1dd9

lines 314–320why, one step back
314 )
315}316317#[test]318fn verify_app() {319 build_command().debug_assert();320}