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
Provenance
- Commit
8d38ef3- Tree
603d8a3- Author
Benjamin Rombaut <benjamin.rombaut@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
27ec9e2
4 files changed+63 added−94 removed
modified:src/cli.rs+5 added-7 removed
1 use std::ffi::OsString;2 3-use clap::{crate_version, AppSettings, Arg, ArgMatches, Command, builder::NonEmptyStringValueParser, ArgAction};3+use clap::{crate_version, Arg, ArgMatches, Command, builder::NonEmptyStringValueParser, ArgAction};4 5 pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches6 where7 I: IntoIterator<Item = T>,3 unmodified lines11 command.get_matches_from(args)12 }13 14 /// Build the clap command for parsing command line arguments15-fn build_command() -> Command<'static> {15+fn 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 lines26 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 lines84 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 lines286 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 linesmodified:src/command.rs+18 added-20 removed
8 unmodified lines9 ParameterNameAndValue,10 },11 };12 13-use clap::ArgMatches;13+use clap::{ArgMatches, parser::ValuesRef};14 15 use crate::parameter::tokenize::tokenize;16 use crate::parameter::ParameterValue;17 18 use anyhow::{bail, Context, Result};19-use clap::Values;19 use rust_decimal::Decimal;20 21 /// A command that should be benchmarked.22 #[derive(Debug, Clone, PartialEq, Eq)]93 unmodified lines116 pub struct Commands<'a>(Vec<Command<'a>>);117 118 impl<'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<_>>();122 124- 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>>());134-135- 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 lines145 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;150 151 let dimensions: Vec<usize> = std::iter::once(command_list.len())152 .chain(153 param_names_and_values52 unmodified lines206 }207 208 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 }214 217- 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 lines282 Ok(commands)283 }284 285 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();296 297 // attempt to parse as integers298 if let (Ok(param_min), Ok(param_max), Ok(step)) = (299 param_min.parse::<i32>(),236 unmodified linesmodified:Cargo.lock+36 added-63 removed
11 unmodified lines12 ]13 14 [[package]]15 name = "anyhow"16-version = "1.0.65"16+version = "1.0.66"17 source = "registry+https://github.com/rust-lang/crates.io-index"18-checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602"18+checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"19 20 [[package]]21 name = "approx"22 version = "0.5.1"10 unmodified lines33 checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"34 35 [[package]]36 name = "assert_cmd"37-version = "2.0.4"37+version = "2.0.5"38 source = "registry+https://github.com/rust-lang/crates.io-index"39-checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e"39+checksum = "d5c2ca00549910ec251e3bd15f87aeeb206c9456b9a77b43ff6c97c54042a472"40 dependencies = [41 "bstr",42 "doc-comment",43 "predicates",59 unmodified lines103 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"104 105 [[package]]106 name = "clap"107-version = "3.2.22"107+version = "4.0.18"108 source = "registry+https://github.com/rust-lang/crates.io-index"109-checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"109+checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"110 dependencies = [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 ]119 120 [[package]]121 name = "clap_complete"124-version = "3.2.5"122+version = "4.0.3"123 source = "registry+https://github.com/rust-lang/crates.io-index"126-checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8"124+checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3"125 dependencies = [126 "clap",127 ]128 129 [[package]]130 name = "clap_lex"133-version = "0.2.4"131+version = "0.3.0"132 source = "registry+https://github.com/rust-lang/crates.io-index"135-checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"133+checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"134 dependencies = [135 "os_str_bytes",136 ]137 18 unmodified lines156 ]157 158 [[package]]159 name = "console"162-version = "0.15.1"160+version = "0.15.2"161 source = "registry+https://github.com/rust-lang/crates.io-index"164-checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847"162+checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c"163 dependencies = [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 lines261 checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"262 263 [[package]]264 name = "getrandom"267-version = "0.2.7"265+version = "0.2.8"266 source = "registry+https://github.com/rust-lang/crates.io-index"269-checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"267+checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"268 dependencies = [269 "cfg-if",270 "libc",271 "wasi",272 ]273 274 [[package]]277-name = "hashbrown"278-version = "0.12.3"279-source = "registry+https://github.com/rust-lang/crates.io-index"280-checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"281-282-[[package]]275 name = "hermit-abi"276 version = "0.1.19"277 source = "registry+https://github.com/rust-lang/crates.io-index"278 checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"29 unmodified lines308 "winapi",309 ]310 311 [[package]]320-name = "indexmap"321-version = "1.9.1"322-source = "registry+https://github.com/rust-lang/crates.io-index"323-checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"324-dependencies = [325- "autocfg 1.1.0",326- "hashbrown",327-]328-329-[[package]]312 name = "indicatif"313 version = "0.17.1"314 source = "registry+https://github.com/rust-lang/crates.io-index"315 checksum = "bfddc9561e8baf264e0e45e197fd7696320026eb10a8180340debc27b18f535b"13 unmodified lines329 ]330 331 [[package]]332 name = "io-lifetimes"351-version = "0.7.3"333+version = "0.7.4"334 source = "registry+https://github.com/rust-lang/crates.io-index"353-checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06"335+checksum = "e6e481ccbe3dea62107216d0d1138bb8ad8e5e5c43009a098bd1990272c497b0"336 337 [[package]]338 name = "itertools"339 version = "0.10.5"10 unmodified lines350 checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"351 352 [[package]]353 name = "itoa"372-version = "1.0.3"354+version = "1.0.4"355 source = "registry+https://github.com/rust-lang/crates.io-index"374-checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"356+checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"357 358 [[package]]359 name = "lazy_static"360 version = "1.4.0"137 unmodified lines498 checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"499 500 [[package]]501 name = "os_str_bytes"520-version = "6.3.0"502+version = "6.3.1"503 source = "registry+https://github.com/rust-lang/crates.io-index"522-checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"504+checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9"505 506 [[package]]507 name = "pin-utils"508 version = "0.1.0"37 unmodified lines546 ]547 548 [[package]]549 name = "proc-macro2"568-version = "1.0.43"550+version = "1.0.47"551 source = "registry+https://github.com/rust-lang/crates.io-index"570-checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"552+checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"553 dependencies = [554 "unicode-ident",555 ]556 204 unmodified lines761 ]762 763 [[package]]764 name = "rustix"783-version = "0.35.10"765+version = "0.35.12"766 source = "registry+https://github.com/rust-lang/crates.io-index"785-checksum = "af895b90e5c071badc3136fc10ff0bcfc98747eadbaf43ed8f214e07ba8f8477"767+checksum = "985947f9b6423159c4726323f373be0a21bdb514c5af06a849cb3d2dce2d01e8"768 dependencies = [769 "bitflags",770 "errno",771 "io-lifetimes",9 unmodified lines781 checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"782 783 [[package]]784 name = "serde"803-version = "1.0.144"785+version = "1.0.147"786 source = "registry+https://github.com/rust-lang/crates.io-index"805-checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"787+checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"788 dependencies = [789 "serde_derive",790 ]791 792 [[package]]793 name = "serde_derive"812-version = "1.0.144"794+version = "1.0.147"795 source = "registry+https://github.com/rust-lang/crates.io-index"814-checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"796+checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"797 dependencies = [798 "proc-macro2",799 "quote",800 "syn",801 ]802 803 [[package]]804 name = "serde_json"823-version = "1.0.85"805+version = "1.0.87"806 source = "registry+https://github.com/rust-lang/crates.io-index"825-checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"807+checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"808 dependencies = [827- "itoa 1.0.3",809+ "itoa 1.0.4",810 "ryu",811 "serde",812 ]813 20 unmodified lines834 checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"835 836 [[package]]837 name = "syn"856-version = "1.0.100"838+version = "1.0.103"839 source = "registry+https://github.com/rust-lang/crates.io-index"858-checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e"840+checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"841 dependencies = [842 "proc-macro2",843 "quote",844 "unicode-ident",48 unmodified lines893 source = "registry+https://github.com/rust-lang/crates.io-index"894 checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"895 896 [[package]]915-name = "textwrap"916-version = "0.15.1"917-source = "registry+https://github.com/rust-lang/crates.io-index"918-checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"919-dependencies = [920- "terminal_size 0.2.1",921-]922-923-[[package]]897 name = "thiserror"898 version = "1.0.37"899 source = "registry+https://github.com/rust-lang/crates.io-index"900 checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"13 unmodified lines914 ]915 916 [[package]]917 name = "unicode-ident"945-version = "1.0.4"918+version = "1.0.5"919 source = "registry+https://github.com/rust-lang/crates.io-index"947-checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"920+checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"921 922 [[package]]923 name = "unicode-width"924 version = "0.1.10"91 unmodified linesmodified:Cargo.toml+4 added-4 removed
40 unmodified lines4142434445454647474849505152535455565657585859606140 unmodified lines[target.'cfg(target_os="linux")'.dependencies]nix = { version = "0.25.0", features = ["zerocopy"] }
[dependencies.clap]version = "3"version = "4.0.18"default-features = falsefeatures = ["suggestions", "color", "wrap_help", "cargo"]features = ["suggestions", "color", "wrap_help", "cargo", "help", "usage", "error-context"]
[dev-dependencies]approx = "0.5"assert_cmd = "2.0"predicates = "2.1"tempfile = "3.3"
[build-dependencies]clap = "3"clap = "4.0.18"atty = "0.2"clap_complete = "3"clap_complete = "4.0.3"
[profile.release]lto = true