From 453b4e97c266fa0084604047f38b92915de66ad5 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Wed, 17 May 2023 21:36:14 -0400 Subject: [PATCH] Update clap --- Cargo.lock | 241 +++++++++++++++++++++++++++++++---------- Cargo.toml | 4 +- kakplugin/src/types.rs | 2 +- src/box_.rs | 2 +- src/incr.rs | 2 +- src/invert.rs | 2 +- src/join.rs | 2 +- src/math_eval.rs | 2 +- src/pad.rs | 2 +- src/rev.rs | 2 +- src/set.rs | 5 +- src/shuf.rs | 2 +- src/sort.rs | 22 ++-- src/trim.rs | 2 +- src/uniq.rs | 2 +- src/xargs.rs | 2 +- src/xlookup.rs | 2 +- 17 files changed, 214 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54e7e4b..1ddf6eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,29 +17,24 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20e59b2ccb4c1ffbbf45af6f493e16ac65a66981c85664f1587816c0b08cd698" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + [[package]] name = "cfg-if" version = "1.0.0" @@ -48,26 +43,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.0.10" +version = "4.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" +checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" dependencies = [ - "atty", - "bitflags", + "bitflags 2.3.1", "clap_derive", - "indexmap", - "lazy_static", - "os_str_bytes", + "clap_lex", + "is-terminal", + "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.0.6" +version = "4.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" +checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" dependencies = [ "heck", "proc-macro-error", @@ -76,6 +69,42 @@ dependencies = [ "syn", ] +[[package]] +name = "clap_lex" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "evalexpr" version = "7.0.1" @@ -93,12 +122,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - [[package]] name = "heck" version = "0.4.0" @@ -107,21 +130,40 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + +[[package]] +name = "io-lifetimes" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" dependencies = [ + "hermit-abi", "libc", + "windows-sys", ] [[package]] -name = "indexmap" -version = "1.8.0" +name = "is-terminal" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ - "autocfg", - "hashbrown", + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", ] [[package]] @@ -137,7 +179,9 @@ version = "0.1.0" dependencies = [ "alphanumeric-sort", "clap", + "either", "evalexpr", + "itertools", "kakplugin", "linked-hash-map", "linked_hash_set", @@ -147,17 +191,11 @@ dependencies = [ "strum_macros", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" -version = "0.2.113" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] name = "linked-hash-map" @@ -174,20 +212,29 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "linux-raw-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" + [[package]] name = "memchr" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + [[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" @@ -221,11 +268,11 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -284,6 +331,20 @@ version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +[[package]] +name = "rustix" +version = "0.37.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.7" @@ -345,10 +406,10 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.14.2" +name = "unicode-ident" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-xid" @@ -398,3 +459,69 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index ddcc8ea..c33e7e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ image = "scratch" [dependencies] regex = "1" -clap = {version = "3", features = ["derive", "env"]} +clap = { version = "4", features = ["derive", "env"] } alphanumeric-sort = "1" # shellwords = {version = "1", path = "../../../git/rust-shellwords/"} # shellwords = "1" @@ -43,6 +43,8 @@ linked-hash-map = "0.5.4" linked_hash_set = "0.1.4" strum_macros = "0.24" strum = { version = "0.24", features = ["derive"] } +itertools = "0.10.5" +either = "1.8.1" [profile.release] lto = true diff --git a/kakplugin/src/types.rs b/kakplugin/src/types.rs index 78124f6..40840db 100644 --- a/kakplugin/src/types.rs +++ b/kakplugin/src/types.rs @@ -71,7 +71,7 @@ pub struct SelectionWithSubselections { // } // } -#[derive(Clone, PartialEq, PartialOrd, Ord, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Debug)] pub struct SelectionDesc { pub left: AnchorPosition, pub right: AnchorPosition, diff --git a/src/box_.rs b/src/box_.rs index 424a578..27e59ac 100644 --- a/src/box_.rs +++ b/src/box_.rs @@ -2,7 +2,7 @@ use kakplugin::{ get_selections_desc, set_selections_desc, AnchorPosition, KakError, SelectionDesc, }; use std::cmp::{max, min}; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { /// Bounding box mode, which selects the largest box to contain everything #[clap(short, long, help = "Select the bonding box of all selections")] diff --git a/src/incr.rs b/src/incr.rs index b25ae07..969bb35 100644 --- a/src/incr.rs +++ b/src/incr.rs @@ -2,7 +2,7 @@ use evalexpr::{eval, Value}; use kakplugin::{get_selections, set_selections, KakError}; use std::borrow::Cow; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(index = 1, help = "Amount to increment/decrement", default_value = "1")] amount: isize, diff --git a/src/invert.rs b/src/invert.rs index df7246b..460faf8 100644 --- a/src/invert.rs +++ b/src/invert.rs @@ -1,7 +1,7 @@ use kakplugin::{ get_selections_desc, set_selections_desc, types::MaybeSplit, KakError, SelectionDesc, }; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(short, long, help = "Do not include newlines")] no_newline: bool, diff --git a/src/join.rs b/src/join.rs index 8a16408..b4d242d 100644 --- a/src/join.rs +++ b/src/join.rs @@ -1,6 +1,6 @@ use kakplugin::{get_selections_desc_unordered, set_selections_desc, KakError}; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options; pub fn join(_options: &Options) -> Result { diff --git a/src/math_eval.rs b/src/math_eval.rs index 8270cec..b45311d 100644 --- a/src/math_eval.rs +++ b/src/math_eval.rs @@ -2,7 +2,7 @@ use evalexpr::{eval, Value}; use kakplugin::{get_selections, set_selections, KakError}; use std::borrow::Cow; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options; pub fn math_eval(_options: &Options) -> Result { let mut err_count: usize = 0; diff --git a/src/pad.rs b/src/pad.rs index 445cb66..fe6b453 100644 --- a/src/pad.rs +++ b/src/pad.rs @@ -2,7 +2,7 @@ use crate::utils::split_newlines; use kakplugin::{get_selections, set_selections, KakError}; use std::borrow::Cow; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(index = 1, help = "Pad with this char", default_value = "0")] fill: char, diff --git a/src/rev.rs b/src/rev.rs index 0279e22..8410601 100644 --- a/src/rev.rs +++ b/src/rev.rs @@ -1,5 +1,5 @@ use kakplugin::{get_selections, set_selections, KakError}; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options; pub fn rev(_options: &Options) -> Result { diff --git a/src/set.rs b/src/set.rs index 400f7ab..312486b 100644 --- a/src/set.rs +++ b/src/set.rs @@ -10,11 +10,10 @@ use std::{borrow::Cow, io::Write, str::FromStr}; const KAK_BUFFER_NAME: &str = "*kakplugin-set*"; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap( - min_values = 1, - max_values = 3, + num_args = 1..=3, allow_hyphen_values = true, help = "Register operation and operand. Empty register is current selection. Example: 'a-b' or '+b'" )] diff --git a/src/shuf.rs b/src/shuf.rs index d9c4f67..403b396 100644 --- a/src/shuf.rs +++ b/src/shuf.rs @@ -1,6 +1,6 @@ use kakplugin::{get_selections, set_selections, KakError}; use rand::{seq::SliceRandom, thread_rng}; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options; pub fn shuf(_options: &Options) -> Result { let mut selections = get_selections(None)?; diff --git a/src/sort.rs b/src/sort.rs index c558373..c06ff56 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -1,9 +1,10 @@ use alphanumeric_sort::compare_str; +use clap::ArgAction; use kakplugin::{self, get_selections_with_desc, open_command_fifo, KakError, SelectionWithDesc}; use regex::Regex; use std::{borrow::Cow, cmp::Ordering, io::Write}; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(index = 1, help = "Optional regex comparison key")] regex: Option, @@ -14,7 +15,8 @@ pub struct Options { )] subselections_register: Option, // TODO: Can we invert a boolean? This name is terrible - #[clap(short = 'S', long, parse(try_from_str = invert_bool), default_value_t, help = "Do not treat trimmed value of selections when sorting")] + // #[clap(short = 'S', long, value_parser = invert_bool, default_value_t, help = "Do not treat trimmed value of selections when sorting")] + #[clap(short = 'S', long, action = ArgAction::SetFalse, default_value_t, help = "Do not treat trimmed value of selections when sorting")] no_skip_whitespace: bool, #[clap(short = 'L', long, help = "Do not sort numbers lexicographically")] no_lexicographic_sort: bool, @@ -24,14 +26,14 @@ pub struct Options { ignore_case: bool, } -fn invert_bool(s: &str) -> Result { - // Invert the boolean - match s { - "false" => Ok(true), - "true" => Ok(false), - _ => Err("Unparsable boolean value"), - } -} +// fn invert_bool(s: &str) -> Result { +// // Invert the boolean +// match s { +// "false" => Ok(true), +// "true" => Ok(false), +// _ => Err("Unparsable boolean value"), +// } +// } struct SortableSelection<'a> { /// The content of the selection diff --git a/src/trim.rs b/src/trim.rs index 6e69b61..73d9227 100644 --- a/src/trim.rs +++ b/src/trim.rs @@ -1,7 +1,7 @@ use kakplugin::{get_selections, open_command_fifo, KakError}; use std::io::Write; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(short, long, help = "Trim from left")] left: bool, diff --git a/src/uniq.rs b/src/uniq.rs index 7ec9bf8..f6d5317 100644 --- a/src/uniq.rs +++ b/src/uniq.rs @@ -6,7 +6,7 @@ use kakplugin::{ use regex::Regex; use std::collections::BTreeSet; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(index = 1, help = "Optional regex to compare unique elements")] regex: Option, diff --git a/src/xargs.rs b/src/xargs.rs index 4d1d0ee..790e0d8 100644 --- a/src/xargs.rs +++ b/src/xargs.rs @@ -3,7 +3,7 @@ use std::{ io::{BufRead, BufReader, Write}, process::{Command, Stdio}, }; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap()] command: String, diff --git a/src/xlookup.rs b/src/xlookup.rs index a1c579f..fff4790 100644 --- a/src/xlookup.rs +++ b/src/xlookup.rs @@ -8,7 +8,7 @@ use std::{ }, }; -#[derive(clap::StructOpt, Debug)] +#[derive(clap::Args, Debug)] pub struct Options { #[clap(help = "Register with the lookup table", default_value = "\"")] register: Register,