Migrate to clap 4

This commit is contained in:
Takashi Kokubun 2023-08-02 23:31:13 -07:00
parent b32e1f7f82
commit e11d4cda7c
3 changed files with 98 additions and 97 deletions

163
Cargo.lock generated
View File

@ -41,6 +41,55 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"
[[package]]
name = "anstyle-parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "anyhow"
version = "1.0.72"
@ -87,17 +136,6 @@ dependencies = [
"syn 2.0.28",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -197,51 +235,59 @@ dependencies = [
[[package]]
name = "clap"
version = "3.2.25"
version = "4.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123"
checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d"
dependencies = [
"atty",
"bitflags 1.3.2",
"clap_builder",
"clap_derive",
"clap_lex",
"indexmap 1.9.3",
"once_cell",
]
[[package]]
name = "clap_builder"
version = "4.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_complete"
version = "3.2.5"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8"
checksum = "5fc443334c81a804575546c5a8a79b4913b50e28d69232903604cada1de817ce"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "3.2.25"
version = "4.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008"
checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.28",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
]
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "concurrent-queue"
@ -606,15 +652,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.2"
@ -737,7 +774,7 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi 0.3.2",
"hermit-abi",
"libc",
"windows-sys",
]
@ -748,7 +785,7 @@ version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi 0.3.2",
"hermit-abi",
"rustix 0.38.4",
"windows-sys",
]
@ -917,7 +954,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi 0.3.2",
"hermit-abi",
"libc",
]
@ -936,12 +973,6 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "os_str_bytes"
version = "6.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac"
[[package]]
name = "parking"
version = "2.1.0"
@ -1024,30 +1055,6 @@ dependencies = [
"toml_edit",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.66"
@ -1392,12 +1399,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
[[package]]
name = "thiserror"
version = "1.0.44"
@ -1516,10 +1517,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa"
[[package]]
name = "version_check"
version = "0.9.4"
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "waker-fn"

View File

@ -8,8 +8,8 @@ license = "MIT"
[dependencies]
anyhow = "1.0.72"
clap = { version = "3.2.25", features = ["derive"] }
clap_complete = "3.2.5"
clap = { version = "4.3.19", features = ["derive"] }
clap_complete = "4.3.2"
derive-where = "1.2.1"
env_logger = "0.10.0"
evdev = "0.12.1"

View File

@ -3,7 +3,7 @@ use crate::device::{device_watcher, get_input_devices, output_device};
use crate::event_handler::EventHandler;
use action_dispatcher::ActionDispatcher;
use anyhow::{anyhow, bail, Context};
use clap::{AppSettings, ArgEnum, IntoApp, Parser};
use clap::{ValueEnum, Parser, CommandFactory};
use clap_complete::Shell;
use client::build_client;
use config::{config_watcher, load_configs};
@ -31,13 +31,13 @@ mod event_handler;
mod tests;
#[derive(Parser, Debug)]
#[clap(version, global_setting(AppSettings::DeriveDisplayOrder))]
struct Opts {
#[clap(version)]
struct Args {
/// Include a device name or path
#[clap(long, use_delimiter = true)]
#[clap(long, use_value_delimiter = true)]
device: Vec<String>,
/// Ignore a device name or path
#[clap(long, use_delimiter = true)]
#[clap(long, use_value_delimiter = true)]
ignore: Vec<String>,
/// Match mice by default
#[clap(long)]
@ -48,9 +48,9 @@ struct Opts {
/// - config: reload the configs automatically
#[clap(
long,
arg_enum,
min_values = 0,
use_delimiter = true,
value_enum,
num_args = 0..,
use_value_delimiter = true,
require_equals = true,
default_missing_value = "device",
verbatim_doc_comment,
@ -65,14 +65,14 @@ struct Opts {
/// You can use them by storing in your shells completion file or by running
/// - in bash: eval "$(xremap --completions bash)"
/// - in fish: xremap --completions fish | source
#[clap(long, arg_enum, display_order = 100, value_name = "SHELL", verbatim_doc_comment)]
#[clap(long, value_enum, display_order = 100, value_name = "SHELL", verbatim_doc_comment)]
completions: Option<Shell>,
/// Config file(s)
#[clap(required_unless_present = "completions", multiple_values = true)]
#[clap(required_unless_present = "completions", num_args = 1..)]
configs: Vec<PathBuf>,
}
#[derive(ArgEnum, Clone, Copy, Debug, PartialEq, Eq)]
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
enum WatchTargets {
/// Device to add new devices automatically
Device,
@ -89,17 +89,17 @@ enum ReloadEvent {
fn main() -> anyhow::Result<()> {
env_logger::init();
let Opts {
let Args {
device: device_filter,
ignore: ignore_filter,
mouse,
watch,
configs,
completions,
} = Opts::parse();
} = Args::parse();
if let Some(shell) = completions {
clap_complete::generate(shell, &mut Opts::into_app(), "xremap", &mut stdout());
clap_complete::generate(shell, &mut Args::command(), "xremap", &mut stdout());
return Ok(());
}