From 10ba34f78b6e7ea70511721353cd841a3a978c09 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Tue, 17 Jan 2023 00:17:50 -0700 Subject: [PATCH] update: Update to clap 4.1 This includes switching to the stable API for getting values grouped by occurrences, and updating tests to match the new error messages. --- Cargo.lock | 58 ++++++++++++++++++++++++++++++++++++++++++------- Cargo.toml | 2 +- src/cli.rs | 4 ++-- src/exec/mod.rs | 10 +++++---- tests/tests.rs | 16 ++++++++++---- 5 files changed, 71 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 207dd8a..a9eb3de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,14 +101,14 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.22" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91b9970d7505127a162fdaa9b96428d28a479ba78c9ec7550a63a5d9863db682" +checksum = "4ec7a4128863c188deefe750ac1d1dfe66c236909f845af04beed823638dc1b2" dependencies = [ - "atty", "bitflags", "clap_derive", "clap_lex", + "is-terminal", "once_cell", "strsim", "termcolor", @@ -126,9 +126,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.21" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ "heck", "proc-macro-error", @@ -473,6 +473,28 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e481ccbe3dea62107216d0d1138bb8ad8e5e5c43009a098bd1990272c497b0" +[[package]] +name = "io-lifetimes" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" +dependencies = [ + "libc", + "windows-sys 0.42.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes 1.0.4", + "rustix 0.36.6", + "windows-sys 0.42.0", +] + [[package]] name = "jemalloc-sys" version = "0.5.2+5.3.0-patched" @@ -530,6 +552,12 @@ version = "0.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "log" version = "0.4.17" @@ -739,12 +767,26 @@ checksum = "985947f9b6423159c4726323f373be0a21bdb514c5af06a849cb3d2dce2d01e8" dependencies = [ "bitflags", "errno", - "io-lifetimes", + "io-lifetimes 0.7.4", "libc", - "linux-raw-sys", + "linux-raw-sys 0.0.46", "windows-sys 0.36.1", ] +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes 1.0.4", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.42.0", +] + [[package]] name = "same-file" version = "1.0.6" @@ -806,7 +848,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1" dependencies = [ - "rustix", + "rustix 0.35.12", "windows-sys 0.36.1", ] diff --git a/Cargo.toml b/Cargo.toml index 7f258c9..9a4e39c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ clap_complete = {version = "4.0.6", optional = true} faccess = "0.2.4" [dependencies.clap] -version = "4.0.22" +version = "4.1.1" features = ["suggestions", "color", "wrap_help", "cargo", "unstable-grouped", "derive"] [dependencies.chrono] diff --git a/src/cli.rs b/src/cli.rs index 8e97f1c..2e21bf6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -738,11 +738,11 @@ pub struct Exec { impl clap::FromArgMatches for Exec { fn from_arg_matches(matches: &ArgMatches) -> clap::error::Result { let command = matches - .grouped_values_of("exec") + .get_occurrences::("exec") .map(CommandSet::new) .or_else(|| { matches - .grouped_values_of("exec_batch") + .get_occurrences::("exec_batch") .map(CommandSet::new_batch) }) .transpose() diff --git a/src/exec/mod.rs b/src/exec/mod.rs index 167368b..17060b3 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -39,9 +39,10 @@ pub struct CommandSet { } impl CommandSet { - pub fn new(input: I) -> Result + pub fn new(input: I) -> Result where - I: IntoIterator>, + I: IntoIterator, + T: IntoIterator, S: AsRef, { Ok(CommandSet { @@ -53,9 +54,10 @@ impl CommandSet { }) } - pub fn new_batch(input: I) -> Result + pub fn new_batch(input: I) -> Result where - I: IntoIterator>, + I: IntoIterator, + T: IntoIterator, S: AsRef, { Ok(CommandSet { diff --git a/tests/tests.rs b/tests/tests.rs index 5036afd..20de3d8 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1708,18 +1708,26 @@ fn test_exec_batch() { \n\ Usage: fd [OPTIONS] [pattern] [path]...\n\ \n\ - For more information try '--help'\n\ + For more information, try '--help'.\n\ ", ); te.assert_failure_with_error( &["foo", "--exec-batch", "echo", "{/}", ";", "-x", "echo"], - "error: The argument '--exec-batch ...' cannot be used with '--exec ...'", + "error: the argument '--exec-batch ...' cannot be used with '--exec ...'\n\ + \n\ + Usage: fd --exec-batch ... [path]...\n\ + \n\ + For more information, try '--help'.\n\ + ", ); te.assert_failure_with_error( &["foo", "--exec-batch"], - "error: The argument '--exec-batch ...' requires a value but none was supplied", + "error: a value is required for '--exec-batch ...' but none was supplied\n\ + \n\ + For more information, try '--help'.\n\ + ", ); te.assert_failure_with_error( @@ -1728,7 +1736,7 @@ fn test_exec_batch() { \n\ Usage: fd [OPTIONS] [pattern] [path]...\n\ \n\ - For more information try '--help'\n\ + For more information, try '--help'.\n\ ", );