diff options
author | Neal H. Walfield <neal@pep.foundation> | 2023-10-27 14:59:31 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2023-10-27 14:59:31 +0200 |
commit | 200dcb6365585a1188ec86042e3a97905f3d16b1 (patch) | |
tree | d2a9d4f4d7ca1a9d4c1c589822efe134a8bf7409 | |
parent | ebc636a13be56e1beac751d75ccd13305917fa9d (diff) |
ipc: Upgrade clap
- Upgrade clap from clap 3 to clap 4.
- Use the opportunity to change to clap's derive-style API.
-rw-r--r-- | Cargo.lock | 174 | ||||
-rw-r--r-- | ipc/Cargo.toml | 2 | ||||
-rw-r--r-- | ipc/examples/assuan-client.rs | 59 | ||||
-rw-r--r-- | ipc/examples/gpg-agent-client.rs | 66 | ||||
-rw-r--r-- | ipc/examples/gpg-agent-decrypt.rs | 53 | ||||
-rw-r--r-- | ipc/examples/gpg-agent-sign.rs | 54 |
6 files changed, 284 insertions, 124 deletions
@@ -84,12 +84,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[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.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" [[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] name = "anyhow" version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -116,17 +159,6 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -457,26 +489,13 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "atty", - "bitflags 1.3.2", - "clap_lex 0.2.4", - "indexmap 1.9.3", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap" version = "4.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb690e81c7840c0d7aade59f242ea3b41b9bc27bcd5997890e7702ae4b32e487" dependencies = [ "clap_builder", + "clap_derive", + "once_cell", ] [[package]] @@ -485,17 +504,23 @@ version = "4.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ed2e96bc16d8d740f6f48d663eddf4b8a0983e79210fd55479b7bcd0a69860e" dependencies = [ + "anstream", "anstyle", - "clap_lex 0.5.0", + "clap_lex", + "strsim", + "terminal_size", ] [[package]] -name = "clap_lex" -version = "0.2.4" +name = "clap_derive" +version = "4.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" dependencies = [ - "os_str_bytes", + "heck", + "proc-macro2", + "quote", + "syn 2.0.38", ] [[package]] @@ -516,6 +541,12 @@ dependencies = [ ] [[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] name = "const-oid" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -564,7 +595,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.3.24", + "clap", "criterion-plot", "is-terminal", "itertools", @@ -1245,15 +1276,6 @@ 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.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" @@ -1442,6 +1464,17 @@ dependencies = [ ] [[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] name = "ipconfig" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1465,8 +1498,8 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.3", - "rustix", + "hermit-abi", + "rustix 0.38.21", "windows-sys", ] @@ -1567,6 +1600,12 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "linux-raw-sys" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" @@ -1795,7 +1834,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi", "libc", ] @@ -1871,12 +1910,6 @@ dependencies = [ ] [[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - -[[package]] name = "p256" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2352,6 +2385,20 @@ dependencies = [ [[package]] name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys", +] + +[[package]] +name = "rustix" version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" @@ -2359,7 +2406,7 @@ dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.10", "windows-sys", ] @@ -2465,7 +2512,7 @@ dependencies = [ "anyhow", "buffered-reader", "capnp-rpc", - "clap 3.2.25", + "clap", "crossbeam-utils", "ctor", "dirs", @@ -2789,7 +2836,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.4.1", - "rustix", + "rustix 0.38.21", "windows-sys", ] @@ -2805,21 +2852,16 @@ dependencies = [ ] [[package]] -name = "termcolor" -version = "1.3.0" +name = "terminal_size" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237" dependencies = [ - "winapi-util", + "rustix 0.37.27", + "windows-sys", ] [[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.50" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3129,6 +3171,12 @@ dependencies = [ ] [[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/ipc/Cargo.toml b/ipc/Cargo.toml index 4cf078f3..94a7c84b 100644 --- a/ipc/Cargo.toml +++ b/ipc/Cargo.toml @@ -49,7 +49,7 @@ ctor = "0.1" lalrpop = { version = ">=0.17, <0.21", default-features = false } [dev-dependencies] -clap = "3" +clap = { version = "4", features = ["derive", "env", "string", "wrap_help"] } quickcheck = { version = "1", default-features = false } tokio = { version = "1", features = [ "macros" ] } diff --git a/ipc/examples/assuan-client.rs b/ipc/examples/assuan-client.rs index aa7f3ed8..5fb0dc93 100644 --- a/ipc/examples/assuan-client.rs +++ b/ipc/examples/assuan-client.rs @@ -1,24 +1,53 @@ +use std::path::PathBuf; + +use clap::CommandFactory; +use clap::FromArgMatches; +use clap::Parser; + use futures::StreamExt; use sequoia_ipc as ipc; use crate::ipc::assuan::Client; -fn main() { - let matches = clap::App::new("assuan-client") - .version(env!("CARGO_PKG_VERSION")) - .about("Connects to and sends commands to assuan servers.") - .arg(clap::Arg::with_name("server").value_name("PATH") - .required(true) - .help("Server to connect to")) - .arg(clap::Arg::with_name("commands").value_name("COMMAND") - .required(true) - .multiple(true) - .help("Commands to send to the server")) - .get_matches(); +use sequoia_openpgp as openpgp; +use openpgp::Result; + +/// Defines the CLI. +#[derive(Parser, Debug)] +#[clap( + name = "assuan-client", + about = "Connects to and sends commands to assuan servers.", +)] +pub struct Cli { + #[clap( + long, + value_name = "PATH", + help = "Server to connect to", + )] + server: PathBuf, + + #[clap( + long, + value_name = "COMMAND", + help = "Commands to send to the server", + required = true, + )] + commands: Vec<String>, +} + +fn main() -> Result<()> { + let version = format!( + "{} (sequoia-openpgp {}, using {})", + env!("CARGO_PKG_VERSION"), + sequoia_openpgp::VERSION, + sequoia_openpgp::crypto::backend() + ); + let cli = Cli::command().version(version); + let matches = Cli::from_arg_matches(&cli.get_matches())?; let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { - let mut c = Client::connect(matches.value_of("server").unwrap()).await.unwrap(); - for command in matches.values_of("commands").unwrap() { + let mut c = Client::connect(matches.server).await.unwrap(); + for command in matches.commands { eprintln!("> {}", command); c.send(command).unwrap(); while let Some(response) = c.next().await { @@ -26,4 +55,6 @@ fn main() { } } }); + + Ok(()) } diff --git a/ipc/examples/gpg-agent-client.rs b/ipc/examples/gpg-agent-client.rs index 8f2d7415..6e4067c7 100644 --- a/ipc/examples/gpg-agent-client.rs +++ b/ipc/examples/gpg-agent-client.rs @@ -1,33 +1,63 @@ /// Connects to and sends commands to gpg-agent. +use std::path::PathBuf; + +use clap::CommandFactory; +use clap::FromArgMatches; +use clap::Parser; + use futures::StreamExt; + use sequoia_ipc as ipc; use crate::ipc::gnupg::{Context, Agent}; -fn main() { - let matches = clap::App::new("gpg-agent-client") - .version(env!("CARGO_PKG_VERSION")) - .about("Connects to and sends commands to gpg-agent.") - .arg(clap::Arg::with_name("homedir").value_name("PATH") - .long("homedir") - .help("Use this GnuPG home directory, default: $GNUPGHOME")) - .arg(clap::Arg::with_name("commands").value_name("COMMAND") - .required(true) - .multiple(true) - .help("Commands to send to the server")) - .get_matches(); - - let ctx = if let Some(homedir) = matches.value_of("homedir") { - Context::with_homedir(homedir).unwrap() +use sequoia_openpgp as openpgp; +use openpgp::Result; + +/// Defines the CLI. +#[derive(Parser, Debug)] +#[clap( + name = "gpg-agent-client", + about = "Connects to and sends commands to gpg-agent.", +)] +pub struct Cli { + #[clap( + long, + value_name = "PATH", + env = "GNUPGHOME", + help = "Use this GnuPG home directory, default: $GNUPGHOME", + )] + homedir: Option<PathBuf>, + + #[clap( + long, + value_name = "commands", + help = "Commands to send to the server", + required = true, + )] + commands: Vec<String>, +} + +fn main() -> Result<()> { + let version = format!( + "{} (sequoia-openpgp {}, using {})", + env!("CARGO_PKG_VERSION"), + sequoia_openpgp::VERSION, + sequoia_openpgp::crypto::backend()); + let cli = Cli::command().version(version); + let matches = Cli::from_arg_matches(&cli.get_matches())?; + + let ctx = if let Some(homedir) = matches.homedir { + Context::with_homedir(homedir)? } else { - Context::new().unwrap() + Context::new()? }; let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let mut agent = Agent::connect(&ctx).await.unwrap(); - for command in matches.values_of("commands").unwrap() { + for command in matches.commands { eprintln!("> {}", command); agent.send(command).unwrap(); while let Some(response) = agent.next().await { @@ -35,4 +65,6 @@ fn main() { } } }); + + Ok(()) } diff --git a/ipc/examples/gpg-agent-decrypt.rs b/ipc/examples/gpg-agent-decrypt.rs index ebb311ac..f0777718 100644 --- a/ipc/examples/gpg-agent-decrypt.rs +++ b/ipc/examples/gpg-agent-decrypt.rs @@ -2,6 +2,11 @@ use std::collections::HashMap; use std::io; +use std::path::PathBuf; + +use clap::CommandFactory; +use clap::FromArgMatches; +use clap::Parser; use sequoia_openpgp as openpgp; use sequoia_ipc as ipc; @@ -25,22 +30,42 @@ use openpgp::policy::Policy; use openpgp::policy::StandardPolicy as P; use ipc::gnupg::{Context, KeyPair}; +/// Defines the CLI. +#[derive(Parser, Debug)] +#[clap( + name = "gpg-agent-decrypt", + about = "Connects to gpg-agent and decrypts a message.", +)] +pub struct Cli { + #[clap( + long, + value_name = "PATH", + env = "GNUPGHOME", + help = "Use this GnuPG home directory, default: $GNUPGHOME", + )] + homedir: Option<PathBuf>, + + #[clap( + long, + value_name = "CERT", + help = "Public part of the secret keys managed by gpg-agent", + required = true, + )] + cert: Vec<PathBuf>, +} + fn main() -> openpgp::Result<()> { let p = &P::new(); - let matches = clap::App::new("gpg-agent-decrypt") - .version(env!("CARGO_PKG_VERSION")) - .about("Connects to gpg-agent and decrypts a message.") - .arg(clap::Arg::with_name("homedir").value_name("PATH") - .long("homedir") - .help("Use this GnuPG home directory, default: $GNUPGHOME")) - .arg(clap::Arg::with_name("cert").value_name("Cert") - .required(true) - .multiple(true) - .help("Public part of the secret keys managed by gpg-agent")) - .get_matches(); - - let ctx = if let Some(homedir) = matches.value_of("homedir") { + let version = format!( + "{} (sequoia-openpgp {}, using {})", + env!("CARGO_PKG_VERSION"), + sequoia_openpgp::VERSION, + sequoia_openpgp::crypto::backend()); + let cli = Cli::command().version(version); + let matches = Cli::from_arg_matches(&cli.get_matches())?; + + let ctx = if let Some(homedir) = matches.homedir { Context::with_homedir(homedir)? } else { Context::new()? @@ -48,7 +73,7 @@ fn main() -> openpgp::Result<()> { // Read the Certs from the given files. let certs = - matches.values_of("cert").expect("required").map( + matches.cert.into_iter().map( openpgp::Cert::from_file ).collect::<Result<_, _>>()?; diff --git a/ipc/examples/gpg-agent-sign.rs b/ipc/examples/gpg-agent-sign.rs index b3204ec9..6e27c239 100644 --- a/ipc/examples/gpg-agent-sign.rs +++ b/ipc/examples/gpg-agent-sign.rs @@ -1,6 +1,11 @@ /// Signs data using the openpgp crate and secrets in gpg-agent. use std::io; +use std::path::PathBuf; + +use clap::CommandFactory; +use clap::FromArgMatches; +use clap::Parser; use sequoia_openpgp as openpgp; use sequoia_ipc as ipc; @@ -10,30 +15,49 @@ use openpgp::serialize::stream::{Armorer, Message, LiteralWriter, Signer}; use openpgp::policy::StandardPolicy as P; use ipc::gnupg::{Context, KeyPair}; +/// Defines the CLI. +#[derive(Parser, Debug)] +#[clap( + name = "gpg-agent-sign", + about = "Connects to gpg-agent and creates a dummy signature.", +)] +pub struct Cli { + #[clap( + long, + value_name = "PATH", + env = "GNUPGHOME", + help = "Use this GnuPG home directory, default: $GNUPGHOME", + )] + homedir: Option<PathBuf>, + + #[clap( + long, + value_name = "CERT", + help = "Public part of the secret keys managed by gpg-agent", + required = true, + )] + cert: Vec<PathBuf>, +} + fn main() -> openpgp::Result<()> { let p = &P::new(); - let matches = clap::App::new("gpg-agent-sign") - .version(env!("CARGO_PKG_VERSION")) - .about("Connects to gpg-agent and creates a dummy signature.") - .arg(clap::Arg::with_name("homedir").value_name("PATH") - .long("homedir") - .help("Use this GnuPG home directory, default: $GNUPGHOME")) - .arg(clap::Arg::with_name("cert").value_name("Cert") - .required(true) - .multiple(true) - .help("Public part of the secret keys managed by gpg-agent")) - .get_matches(); - - let ctx = if let Some(homedir) = matches.value_of("homedir") { + let version = format!( + "{} (sequoia-openpgp {}, using {})", + env!("CARGO_PKG_VERSION"), + sequoia_openpgp::VERSION, + sequoia_openpgp::crypto::backend()); + let cli = Cli::command().version(version); + let matches = Cli::from_arg_matches(&cli.get_matches())?; + + let ctx = if let Some(homedir) = matches.homedir { Context::with_homedir(homedir)? } else { Context::new()? }; // Read the Certs from the given files. - let certs = - matches.values_of("cert").expect("required").map( + let certs = matches.cert.into_iter().map( openpgp::Cert::from_file ).collect::<Result<Vec<_>, _>>()?; |