Update to clap 3

This commit is contained in:
David Peter 2022-02-03 20:50:39 +01:00 committed by David Peter
parent f619511101
commit 80a9f51710
7 changed files with 163 additions and 138 deletions

View File

@ -1,7 +1,7 @@
name: CICD
env:
MIN_SUPPORTED_RUST_VERSION: "1.51.0"
MIN_SUPPORTED_RUST_VERSION: "1.54.0"
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
on:

156
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.18"
@ -9,20 +11,11 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "approx"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
@ -96,18 +89,28 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.34.0"
version = "3.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
checksum = "b63edc3f163b3c71ec8aa23f9bd6070f77edbf3d1d198b164afa90ff00e4ec62"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim",
"term_size",
"termcolor",
"terminal_size",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap_complete"
version = "3.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4dabb7e2f006497e1da045feaa512acf0686f76b68d94925da2d9422dcb521"
dependencies = [
"clap",
]
[[package]]
@ -215,15 +218,21 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "getrandom"
version = "0.2.3"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -241,6 +250,7 @@ dependencies = [
"assert_cmd",
"atty",
"clap",
"clap_complete",
"colored",
"csv",
"indicatif",
@ -256,6 +266,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "indexmap"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg 1.0.1",
"hashbrown",
]
[[package]]
name = "indicatif"
version = "0.16.2"
@ -279,9 +299,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.10.1"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [
"either",
]
@ -306,9 +326,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.116"
version = "0.2.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
[[package]]
name = "memchr"
@ -407,15 +427,24 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "once_cell"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]]
name = "ppv-lite86"
version = "0.2.14"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3ca011bd0129ff4ae15cd04c4eef202cadf6c51c21e47aba319b4e0501db741"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "predicates"
@ -433,15 +462,15 @@ dependencies = [
[[package]]
name = "predicates-core"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb"
[[package]]
name = "predicates-tree"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "338c7be2905b732ae3984a2f40032b5e94fd8f52505b186c7d4d68d193445df7"
checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032"
dependencies = [
"predicates-core",
"termtree",
@ -449,18 +478,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.30"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
dependencies = [
"proc-macro2",
]
@ -663,9 +692,9 @@ dependencies = [
[[package]]
name = "rust_decimal"
version = "1.19.0"
version = "1.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c2d4912d369fb95a351c221475657970678d344d70c1a788223f6e74d1e3732"
checksum = "4214023b1223d02a4aad9f0bb9828317634a56530870a2eaf7200a99c0c10f68"
dependencies = [
"arrayvec",
"num-traits",
@ -674,9 +703,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.5"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "serde"
@ -727,15 +756,15 @@ dependencies = [
[[package]]
name = "strsim"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.80"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
dependencies = [
"proc-macro2",
"quote",
@ -757,13 +786,12 @@ dependencies = [
]
[[package]]
name = "term_size"
version = "0.3.2"
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"libc",
"winapi",
"winapi-util",
]
[[package]]
@ -778,38 +806,25 @@ dependencies = [
[[package]]
name = "termtree"
version = "0.2.1"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78fbf2dd23e79c28ccfa2472d3e6b3b189866ffef1aeb91f17c2d968b6586378"
checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
[[package]]
name = "textwrap"
version = "0.11.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
dependencies = [
"term_size",
"unicode-width",
"terminal_size",
]
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "wait-timeout"
version = "0.2.0"
@ -841,6 +856,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View File

@ -30,9 +30,9 @@ libc = "0.2"
winapi = { version = "0.3", features = ["processthreadsapi", "minwindef", "winnt"] }
[dependencies.clap]
version = "2"
version = "3"
default-features = false
features = ["suggestions", "color", "wrap_help"]
features = ["suggestions", "color", "wrap_help", "cargo"]
[dev-dependencies]
approx = "0.5"
@ -41,8 +41,9 @@ predicates = "2.1"
tempfile = "3.3"
[build-dependencies]
clap = "2"
clap = "3"
atty = "0.2"
clap_complete = "3.0"
[profile.release]
lto = true

View File

@ -208,7 +208,7 @@ Hyperfine can be installed via [cargo](https://doc.rust-lang.org/cargo/):
cargo install hyperfine
```
Make sure that you use Rust 1.51 or higher.
Make sure that you use Rust 1.54 or higher.
### From binaries (Linux, macOS, Windows)

View File

@ -1,6 +1,6 @@
use std::fs;
use clap::Shell;
use clap_complete::{generate_to, Shell};
include!("src/app.rs");
@ -13,8 +13,13 @@ fn main() {
fs::create_dir_all(&outdir).unwrap();
let mut app = build_app();
app.gen_completions("hyperfine", Shell::Bash, &outdir);
app.gen_completions("hyperfine", Shell::Fish, &outdir);
app.gen_completions("hyperfine", Shell::Zsh, &outdir);
app.gen_completions("hyperfine", Shell::PowerShell, &outdir);
for shell in [
Shell::Bash,
Shell::Fish,
Shell::Zsh,
Shell::PowerShell,
Shell::Elvish,
] {
generate_to(shell, &mut app, "hyperfine", &outdir).unwrap();
}
}

View File

@ -1,45 +1,38 @@
use std::ffi::OsString;
use atty::Stream;
use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
pub fn get_arg_matches<I, T>(args: I) -> ArgMatches<'static>
pub fn get_arg_matches<'a, I, T>(args: I) -> ArgMatches
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
T: Into<OsString> + Clone + 'a,
{
let app = build_app();
app.get_matches_from(args)
}
/// Build the clap app for parsing command line arguments
fn build_app() -> App<'static, 'static> {
let clap_color_setting = if atty::is(Stream::Stdout) {
AppSettings::ColoredHelp
} else {
AppSettings::ColorNever
};
fn build_app() -> App<'static> {
App::new("hyperfine")
.version(crate_version!())
.setting(clap_color_setting)
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::UnifiedHelpMessage)
.setting(AppSettings::NextLineHelp)
.setting(AppSettings::HidePossibleValuesInHelp)
.setting(AppSettings::HidePossibleValues)
.max_term_width(90)
.about("A command-line benchmarking tool.")
.arg(
Arg::with_name("command")
.help("Command to benchmark")
Arg::new("command")
.help("Command to benchmark. This can be the name of an executable or a shell \
command like \"sleep 0.5 && echo test\". If multiple commands are given, \
hyperfine will show a comparison of the respective runtimes.")
.required(true)
.multiple(true)
.empty_values(false),
.multiple_occurrences(true)
.forbid_empty_values(true),
)
.arg(
Arg::with_name("warmup")
Arg::new("warmup")
.long("warmup")
.short("w")
.short('w')
.takes_value(true)
.value_name("NUM")
.help(
@ -48,35 +41,35 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("min-runs")
Arg::new("min-runs")
.long("min-runs")
.short("m")
.short('m')
.takes_value(true)
.value_name("NUM")
.help("Perform at least NUM runs for each command (default: 10)."),
)
.arg(
Arg::with_name("max-runs")
Arg::new("max-runs")
.long("max-runs")
.short("M")
.short('M')
.takes_value(true)
.value_name("NUM")
.help("Perform at most NUM runs for each command. By default, there is no limit."),
)
.arg(
Arg::with_name("runs")
Arg::new("runs")
.long("runs")
.conflicts_with_all(&["max-runs", "min-runs"])
.short("r")
.short('r')
.takes_value(true)
.value_name("NUM")
.help("Perform exactly NUM runs for each command. If this option is not specified, \
hyperfine automatically determines the number of runs."),
)
.arg(
Arg::with_name("setup")
Arg::new("setup")
.long("setup")
.short("s")
.short('s')
.takes_value(true)
.number_of_values(1)
.value_name("CMD")
@ -88,11 +81,11 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("prepare")
Arg::new("prepare")
.long("prepare")
.short("p")
.short('p')
.takes_value(true)
.multiple(true)
.multiple_occurrences(true)
.number_of_values(1)
.value_name("CMD")
.help(
@ -104,9 +97,9 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("cleanup")
Arg::new("cleanup")
.long("cleanup")
.short("c")
.short('c')
.takes_value(true)
.value_name("CMD")
.help(
@ -117,9 +110,9 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("parameter-scan")
Arg::new("parameter-scan")
.long("parameter-scan")
.short("P")
.short('P')
.takes_value(true)
.allow_hyphen_values(true)
.value_names(&["VAR", "MIN", "MAX"])
@ -135,9 +128,9 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("parameter-step-size")
Arg::new("parameter-step-size")
.long("parameter-step-size")
.short("D")
.short('D')
.takes_value(true)
.value_names(&["DELTA"])
.requires("parameter-scan")
@ -149,11 +142,11 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("parameter-list")
Arg::new("parameter-list")
.long("parameter-list")
.short("L")
.short('L')
.takes_value(true)
.multiple(true)
.multiple_occurrences(true)
.allow_hyphen_values(true)
.value_names(&["VAR", "VALUES"])
.conflicts_with_all(&["parameter-scan", "parameter-step-size"])
@ -167,7 +160,7 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("style")
Arg::new("style")
.long("style")
.takes_value(true)
.value_name("TYPE")
@ -182,38 +175,38 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("shell")
Arg::new("shell")
.long("shell")
.short("S")
.short('S')
.takes_value(true)
.value_name("SHELL")
.overrides_with("shell")
.help("Set the shell to use for executing benchmarked commands."),
)
.arg(
Arg::with_name("ignore-failure")
Arg::new("ignore-failure")
.long("ignore-failure")
.short("i")
.short('i')
.help("Ignore non-zero exit codes of the benchmarked programs."),
)
.arg(
Arg::with_name("time-unit")
Arg::new("time-unit")
.long("time-unit")
.short("u")
.short('u')
.takes_value(true)
.value_name("UNIT")
.possible_values(&["millisecond", "second"])
.help("Set the time unit to be used. Possible values: millisecond, second."),
)
.arg(
Arg::with_name("export-asciidoc")
Arg::new("export-asciidoc")
.long("export-asciidoc")
.takes_value(true)
.value_name("FILE")
.help("Export the timing summary statistics as an AsciiDoc table to the given FILE."),
)
.arg(
Arg::with_name("export-csv")
Arg::new("export-csv")
.long("export-csv")
.takes_value(true)
.value_name("FILE")
@ -221,21 +214,21 @@ fn build_app() -> App<'static, 'static> {
the timing results for each individual run, use the JSON export format."),
)
.arg(
Arg::with_name("export-json")
Arg::new("export-json")
.long("export-json")
.takes_value(true)
.value_name("FILE")
.help("Export the timing summary statistics and timings of individual runs as JSON to the given FILE."),
)
.arg(
Arg::with_name("export-markdown")
Arg::new("export-markdown")
.long("export-markdown")
.takes_value(true)
.value_name("FILE")
.help("Export the timing summary statistics as a Markdown table to the given FILE."),
)
.arg(
Arg::with_name("show-output")
Arg::new("show-output")
.long("show-output")
.conflicts_with("style")
.help(
@ -246,15 +239,19 @@ fn build_app() -> App<'static, 'static> {
),
)
.arg(
Arg::with_name("command-name")
Arg::new("command-name")
.long("command-name")
.short("n")
.short('n')
.takes_value(true)
.multiple(true)
.multiple_occurrences(true)
.number_of_values(1)
.value_name("NAME")
.help("Give a meaningful name to a command"),
.help("Give a meaningful name to a command. This can be specified multiple times \
if several commands are benchmarked."),
)
.help_message("Print this help message.")
.version_message("Show version information.")
}
#[test]
fn verify_app() {
build_app().debug_assert();
}

View File

@ -146,9 +146,7 @@ fn main() {
}
/// Build the HyperfineOptions that correspond to the given ArgMatches
fn build_hyperfine_options<'a>(
matches: &ArgMatches<'a>,
) -> Result<HyperfineOptions, OptionsError<'a>> {
fn build_hyperfine_options<'a>(matches: &ArgMatches) -> Result<HyperfineOptions, OptionsError<'a>> {
// Enabled ANSI colors on Windows 10
#[cfg(windows)]
colored::control::set_virtual_terminal(true).unwrap();
@ -245,7 +243,7 @@ fn build_hyperfine_options<'a>(
/// Build the ExportManager that will export the results specified
/// in the given ArgMatches
fn build_export_manager(matches: &ArgMatches<'_>) -> io::Result<ExportManager> {
fn build_export_manager(matches: &ArgMatches) -> io::Result<ExportManager> {
let mut export_manager = ExportManager::default();
{
let mut add_exporter = |flag, exporttype| -> io::Result<()> {
@ -263,7 +261,7 @@ fn build_export_manager(matches: &ArgMatches<'_>) -> io::Result<ExportManager> {
}
/// Build the commands to benchmark
fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec<Command<'a>> {
fn build_commands<'a>(matches: &'a ArgMatches) -> Vec<Command<'a>> {
let command_names = matches.values_of("command-name");
let command_strings = matches.values_of("command").unwrap();