cli.rs
This file
Path
src/cli.rs
328 lines · 14.5 KiB · Rust
Last changed by
Added --stdin-data argumentSteve Neasebefore adoptione38acdb
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)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 24–25why, one step back24 .arg(25 Arg::new("command")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 26–30why, one step back26 .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 back31 .required(true)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 32why, one step back32 .action(ArgAction::Append)add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 33why, one step back33 .value_parser(NonEmptyStringValueParser::new()),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 34–39why, one step back34 )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 back40 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 41–49why, one step back41 .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 back50 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 51–57why, one step back51 .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 back58 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 59–66why, one step back59 .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 back67 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 68–75why, one step back68 .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 back76 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 77–88why, one step back77 .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 back89 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 90why, one step back90 .num_args(1)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 91–103why, one step back91 .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 back104 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 105–116why, one step back105 .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 back117 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 118–134why, one step back118 .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 back135 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 136–148why, one step back136 .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 back149 .action(ArgAction::Append)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 150–164why, one step back150 .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 back165 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 166why, one step back166 .value_name("TYPE")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 167why, one step back167 .value_parser(["auto", "basic", "full", "nocolor", "color", "none"])Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 168–180why, one step back168 .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 back181 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 182–183why, one step back182 .value_name("SHELL")183 .overrides_with("shell")Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 184–186why, one step back184 .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 back187 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 back188 \"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 back195 .action(ArgAction::SetTrue)Switch to --shell=none/-N, do not change the defaultDavid Peterbefore adoption365ff25
lines 196–197why, one step back196 .conflicts_with_all(&["shell", "debug-mode"])197 .help("An alias for '--shell=none'.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 198–201why, one step back198 )199 .arg(200 Arg::new("ignore-failure")201 .long("ignore-failure")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 202why, one step back202 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 203–209why, one step back203 .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 back210 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 211why, one step back211 .value_name("UNIT")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 212why, one step back212 .value_parser(["millisecond", "second"])Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
lines 213–214why, one step back213 .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 back215 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 back216 )217 .arg(218 Arg::new("export-asciidoc")219 .long("export-asciidoc")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 220why, one step back220 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 221why, one step back221 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 222why, one step back222 .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 back223 The output time unit can be changed using the --time-unit option."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 224–227why, one step back224 )225 .arg(226 Arg::new("export-csv")227 .long("export-csv")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 228why, one step back228 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 229–230why, one step back229 .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 back231 the timing results for each individual run, use the JSON export format. \Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 232why, one step back232 The output time unit is always seconds."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 233–236why, one step back233 )234 .arg(235 Arg::new("export-json")236 .long("export-json")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 237why, one step back237 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 238why, one step back238 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 239why, one step back239 .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 back240 The output time unit is always seconds"),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 241–244why, one step back241 )242 .arg(243 Arg::new("export-markdown")244 .long("export-markdown")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 245why, one step back245 .action(ArgAction::Set)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 246why, one step back246 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 247why, one step back247 .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 back248 The output time unit can be changed using the --time-unit option."),Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 249–250why, one step back249 )250 .arg(Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 251–252why, one step back251 Arg::new("export-orgmode")252 .long("export-orgmode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 253why, one step back253 .action(ArgAction::Set)Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 254why, one step back254 .value_name("FILE")Add spaces and shorten promptEngineer-of-Efficiencybefore adoptiond08c393
line 255why, one step back255 .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 back256 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 back257 )258 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 259–260why, one step back259 Arg::new("show-output")260 .long("show-output")add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 261why, one step back261 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 262–270why, one step back262 .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 back271 Arg::new("output")272 .long("output")273 .conflicts_with("show-output")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 274why, one step back274 .action(ArgAction::Set)Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 275–276why, one step back275 .value_name("WHERE")276 .help(Clarify --output's help textTavian Barnesbefore adoptiondfd1046
lines 277–282why, one step back277 "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 back283 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 back284 <FILE>: Write the output to the given file.",285 ),286 )287 .arg(Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 288–290why, one step back288 Arg::new("command-name")289 .long("command-name")290 .short('n')use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 291why, one step back291 .action(ArgAction::Append)update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 292why, one step back292 .num_args(1)Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 293–296why, one step back293 .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 back297 // 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 back302 .action(ArgAction::Set)Add new (hidden) --min-benchmarking-time optionDavid Peterbefore adoptiondffbdc3
lines 303–307why, one step back303 .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 back308 .arg(309 Arg::new("debug-mode")310 .long("debug-mode")use set and settrueBenjamin Rombautbefore adoption27ec9e2
line 311why, one step back311 .action(ArgAction::SetTrue)Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 312why, one step back312 .hide(true)Add full stop after help messagesDavid Peterbefore adoptionde0ace4
line 313why, one step back313 .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep <time>'.")Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 314why, one step back314 )Added --stdin-data argumentSteve Neasebefore adoptione38acdb
lines 315–322why, one step back315 .arg(316 Arg::new("stdin-data")317 .long("stdin-data")318 .takes_value(true)319 .number_of_values(1)320 .value_name("FILE")321 .help("Path to file containing stdin data to provide to the command"),322 )Update dependenciesDavid Peterbefore adoptionf2f1dd9
lines 323–328why, one step back323}324325#[test]326fn verify_app() {327 build_command().debug_assert();328}