Skip to content
Myr

update to clap 4

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Benjamin Rombaut · committed by David Peter · parent 27ec9e2 · Browse files · 4 files+63 added−94 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+63 added−94 removed

  • other:+63 added−94 removed

4 files+63 added−94 removed

modified:src/cli.rs+5 added-7 removed
1use std::ffi::OsString;23use clap::{crate_version, AppSettings, Arg, ArgMatches, Command, builder::NonEmptyStringValueParser, ArgAction};3use clap::{crate_version, Arg, ArgMatches, Command, builder::NonEmptyStringValueParser, ArgAction};45pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches6where7 I: IntoIterator<Item = T>,
3 unmodified lines
11 command.get_matches_from(args)12}1314/// Build the clap command for parsing command line arguments15fn build_command() -> Command<'static> {15fn build_command() -> Command {16 Command::new("hyperfine")17 .version(crate_version!())18 .setting(AppSettings::DeriveDisplayOrder)18 .next_line_help(true)19 .hide_possible_values(true)20 .max_term_width(90)21 .about("A command-line benchmarking tool.")
4 unmodified lines
26 The latter is only available if the shell is not explicitly disabled via \27 '--shell=none'. If multiple commands are given, hyperfine will show a \28 comparison of the respective runtimes.")29 .required(true)31 .action(ArgAction::StoreValue)32 .multiple_occurrences(true)30 .action(ArgAction::Append)31 .value_parser(NonEmptyStringValueParser::new()),32 )33 .arg(34 Arg::new("warmup")
49 unmodified lines
84 Arg::new("prepare")85 .long("prepare")86 .short('p')87 .action(ArgAction::Append)90 .number_of_values(1)88 .num_args(1)89 .value_name("CMD")90 .help(91 "Execute CMD before each timing run. This is useful for \92 clearing disk caches, for example.\nThe --prepare option can \
193 unmodified lines
286 Arg::new("command-name")287 .long("command-name")288 .short('n')289 .action(ArgAction::Append)292 .number_of_values(1)290 .num_args(1)291 .value_name("NAME")292 .help("Give a meaningful name to a command. This can be specified multiple times \293 if several commands are benchmarked."),294 )
24 unmodified lines
modified:src/command.rs+18 added-20 removed
8 unmodified lines
9 ParameterNameAndValue,10 },11};1213use clap::ArgMatches;13use clap::{ArgMatches, parser::ValuesRef};1415use crate::parameter::tokenize::tokenize;16use crate::parameter::ParameterValue;1718use anyhow::{bail, Context, Result};19use clap::Values;19use rust_decimal::Decimal;2021/// A command that should be benchmarked.22#[derive(Debug, Clone, PartialEq, Eq)]
93 unmodified lines
116pub struct Commands<'a>(Vec<Command<'a>>);117118impl<'a> Commands<'a> {119 pub fn from_cli_arguments(matches: &'a ArgMatches) -> Result<Commands> {121 let command_names = matches.values_of("command-name");122 let command_strings = matches.values_of("command").unwrap();120 let command_names = matches.get_many::<String>("command-name");121 let command_strings = matches.get_many::<String>("command").unwrap_or_default().map(|v| v.as_str()).collect::<Vec<_>>();122124 if let Some(args) = matches.values_of("parameter-scan") {123 if let Some(args) = matches.get_many::<String>("parameter-scan") {124 let step_size = matches.get_one::<String>("parameter-step-size").map(|s| s.as_str());125 Ok(Self(Self::get_parameter_scan_commands(126 command_names,127 command_strings,128 args,129 step_size,130 )?))132 } else if let Some(args) = matches.values_of("parameter-list") {133 let command_names = command_names.map_or(vec![], |names| names.collect::<Vec<&str>>());134135 let args: Vec<_> = args.collect();131 } else if let Some(args) = matches.get_many::<String>("parameter-list") {132 let command_names = command_names.map_or(vec![], |names| names.map(|v| v.as_str()).collect::<Vec<_>>());133 let args: Vec<_> = args.map(|v| v.as_str()).collect::<Vec<_>>();134 let param_names_and_values: Vec<(&str, Vec<String>)> = args135 .chunks_exact(2)136 .map(|pair| {137 let name = pair[0];
7 unmodified lines
145 if !duplicates.is_empty() {146 bail!("Duplicate parameter names: {}", &duplicates.join(", "));147 }148 }151 let command_list = command_strings.collect::<Vec<&str>>();149 let command_list = command_strings;150151 let dimensions: Vec<usize> = std::iter::once(command_list.len())152 .chain(153 param_names_and_values
52 unmodified lines
206 }207208 Ok(Self(commands))209 } else {212 let command_names = command_names.map_or(vec![], |names| names.collect::<Vec<&str>>());210 let command_names = command_names.map_or(vec![], |names| names.map(|v| v.as_str()).collect::<Vec<_>>());211 if command_names.len() > command_strings.len() {212 return Err(OptionsError::TooManyCommandNames(command_strings.len()).into());213 }214217 let command_list = command_strings.collect::<Vec<&str>>();215 let command_list = command_strings;216 let mut commands = Vec::with_capacity(command_list.len());217 for (i, s) in command_list.iter().enumerate() {218 commands.push(Command::new(command_names.get(i).copied(), s));219 }
62 unmodified lines
282 Ok(commands)283 }284285 fn get_parameter_scan_commands<'b>(288 command_names: Option<Values<'b>>,289 command_strings: Values<'b>,290 mut vals: clap::Values<'b>,286 command_names: Option<ValuesRef<'b, String>>,287 command_strings: Vec<&'b str>,288 mut vals: ValuesRef<'b, String>,289 step: Option<&str>,290 ) -> Result<Vec<Command<'b>>, ParameterScanError> {293 let command_names = command_names.map_or(vec![], |names| names.collect::<Vec<&str>>());294 let command_strings = command_strings.collect::<Vec<&str>>();295 let param_name = vals.next().unwrap();296 let param_min = vals.next().unwrap();297 let param_max = vals.next().unwrap();291 let command_names = command_names.map_or(vec![], |names| names.map(|v| v.as_str()).collect::<Vec<_>>());292 let command_strings = command_strings;293 let param_name = vals.next().unwrap().as_str();294 let param_min = vals.next().unwrap().as_str();295 let param_max = vals.next().unwrap().as_str();296297 // attempt to parse as integers298 if let (Ok(param_min), Ok(param_max), Ok(step)) = (299 param_min.parse::<i32>(),
236 unmodified lines
modified:Cargo.lock+36 added-63 removed
11 unmodified lines
12]1314[[package]]15name = "anyhow"16version = "1.0.65"16version = "1.0.66"17source = "registry+https://github.com/rust-lang/crates.io-index"18checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602"18checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"1920[[package]]21name = "approx"22version = "0.5.1"
10 unmodified lines
33checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"3435[[package]]36name = "assert_cmd"37version = "2.0.4"37version = "2.0.5"38source = "registry+https://github.com/rust-lang/crates.io-index"39checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e"39checksum = "d5c2ca00549910ec251e3bd15f87aeeb206c9456b9a77b43ff6c97c54042a472"40dependencies = [41 "bstr",42 "doc-comment",43 "predicates",
59 unmodified lines
103checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"104105[[package]]106name = "clap"107version = "3.2.22"107version = "4.0.18"108source = "registry+https://github.com/rust-lang/crates.io-index"109checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"109checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"110dependencies = [111 "atty",112 "bitflags",113 "clap_lex",114 "indexmap",114 "once_cell",115 "strsim",116 "termcolor",117 "terminal_size 0.2.1",119 "textwrap",118]119120[[package]]121name = "clap_complete"124version = "3.2.5"122version = "4.0.3"123source = "registry+https://github.com/rust-lang/crates.io-index"126checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8"124checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3"125dependencies = [126 "clap",127]128129[[package]]130name = "clap_lex"133version = "0.2.4"131version = "0.3.0"132source = "registry+https://github.com/rust-lang/crates.io-index"135checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"133checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"134dependencies = [135 "os_str_bytes",136]137
18 unmodified lines
156]157158[[package]]159name = "console"162version = "0.15.1"160version = "0.15.2"161source = "registry+https://github.com/rust-lang/crates.io-index"164checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847"162checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c"163dependencies = [164 "encode_unicode",165 "lazy_static",166 "libc",168 "once_cell",167 "terminal_size 0.1.17",168 "unicode-width",169 "winapi",170]
90 unmodified lines
261checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"262263[[package]]264name = "getrandom"267version = "0.2.7"265version = "0.2.8"266source = "registry+https://github.com/rust-lang/crates.io-index"269checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"267checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"268dependencies = [269 "cfg-if",270 "libc",271 "wasi",272]273274[[package]]277name = "hashbrown"278version = "0.12.3"279source = "registry+https://github.com/rust-lang/crates.io-index"280checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"281282[[package]]275name = "hermit-abi"276version = "0.1.19"277source = "registry+https://github.com/rust-lang/crates.io-index"278checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
29 unmodified lines
308 "winapi",309]310311[[package]]320name = "indexmap"321version = "1.9.1"322source = "registry+https://github.com/rust-lang/crates.io-index"323checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"324dependencies = [325 "autocfg 1.1.0",326 "hashbrown",327]328329[[package]]312name = "indicatif"313version = "0.17.1"314source = "registry+https://github.com/rust-lang/crates.io-index"315checksum = "bfddc9561e8baf264e0e45e197fd7696320026eb10a8180340debc27b18f535b"
13 unmodified lines
329]330331[[package]]332name = "io-lifetimes"351version = "0.7.3"333version = "0.7.4"334source = "registry+https://github.com/rust-lang/crates.io-index"353checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06"335checksum = "e6e481ccbe3dea62107216d0d1138bb8ad8e5e5c43009a098bd1990272c497b0"336337[[package]]338name = "itertools"339version = "0.10.5"
10 unmodified lines
350checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"351352[[package]]353name = "itoa"372version = "1.0.3"354version = "1.0.4"355source = "registry+https://github.com/rust-lang/crates.io-index"374checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"356checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"357358[[package]]359name = "lazy_static"360version = "1.4.0"
137 unmodified lines
498checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"499500[[package]]501name = "os_str_bytes"520version = "6.3.0"502version = "6.3.1"503source = "registry+https://github.com/rust-lang/crates.io-index"522checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"504checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9"505506[[package]]507name = "pin-utils"508version = "0.1.0"
37 unmodified lines
546]547548[[package]]549name = "proc-macro2"568version = "1.0.43"550version = "1.0.47"551source = "registry+https://github.com/rust-lang/crates.io-index"570checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"552checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"553dependencies = [554 "unicode-ident",555]556
204 unmodified lines
761]762763[[package]]764name = "rustix"783version = "0.35.10"765version = "0.35.12"766source = "registry+https://github.com/rust-lang/crates.io-index"785checksum = "af895b90e5c071badc3136fc10ff0bcfc98747eadbaf43ed8f214e07ba8f8477"767checksum = "985947f9b6423159c4726323f373be0a21bdb514c5af06a849cb3d2dce2d01e8"768dependencies = [769 "bitflags",770 "errno",771 "io-lifetimes",
9 unmodified lines
781checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"782783[[package]]784name = "serde"803version = "1.0.144"785version = "1.0.147"786source = "registry+https://github.com/rust-lang/crates.io-index"805checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"787checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"788dependencies = [789 "serde_derive",790]791792[[package]]793name = "serde_derive"812version = "1.0.144"794version = "1.0.147"795source = "registry+https://github.com/rust-lang/crates.io-index"814checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"796checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"797dependencies = [798 "proc-macro2",799 "quote",800 "syn",801]802803[[package]]804name = "serde_json"823version = "1.0.85"805version = "1.0.87"806source = "registry+https://github.com/rust-lang/crates.io-index"825checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"807checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"808dependencies = [827 "itoa 1.0.3",809 "itoa 1.0.4",810 "ryu",811 "serde",812]813
20 unmodified lines
834checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"835836[[package]]837name = "syn"856version = "1.0.100"838version = "1.0.103"839source = "registry+https://github.com/rust-lang/crates.io-index"858checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e"840checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"841dependencies = [842 "proc-macro2",843 "quote",844 "unicode-ident",
48 unmodified lines
893source = "registry+https://github.com/rust-lang/crates.io-index"894checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"895896[[package]]915name = "textwrap"916version = "0.15.1"917source = "registry+https://github.com/rust-lang/crates.io-index"918checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"919dependencies = [920 "terminal_size 0.2.1",921]922923[[package]]897name = "thiserror"898version = "1.0.37"899source = "registry+https://github.com/rust-lang/crates.io-index"900checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
13 unmodified lines
914]915916[[package]]917name = "unicode-ident"945version = "1.0.4"918version = "1.0.5"919source = "registry+https://github.com/rust-lang/crates.io-index"947checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"920checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"921922[[package]]923name = "unicode-width"924version = "0.1.10"
91 unmodified lines
modified:Cargo.toml+4 added-4 removed