diff --git a/Cargo.lock b/Cargo.lock index af8be5cd..dc58a9c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[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 = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -71,17 +119,6 @@ dependencies = [ "syn 2.0.29", ] -[[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" @@ -303,42 +340,43 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.25" +version = "4.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" dependencies = [ - "atty", - "bitflags 1.3.2", + "clap_builder", "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap 1.9.3", - "once_cell", "strsim", - "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.25" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.29", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "codespan-reporting" @@ -350,6 +388,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "colored" version = "2.0.4" @@ -835,15 +879,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" @@ -1163,7 +1198,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", "windows-sys", ] @@ -1444,7 +1479,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", ] @@ -1534,12 +1569,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - [[package]] name = "pairing" version = "0.22.0" @@ -1699,30 +1728,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" @@ -2389,12 +2394,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.47" @@ -2648,6 +2647,12 @@ dependencies = [ "percent-encoding", ] +[[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" diff --git a/Cargo.toml b/Cargo.toml index b5492406..ec9dcc63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ ic-transport-types = { path = "ic-transport-types", version = "0.27.0" } ic-certification = "0.27.0" candid = "0.9.5" +clap = "4.4.3" hex = "0.4.3" leb128 = "0.2.5" ring = "0.16.20" diff --git a/icx-cert/Cargo.toml b/icx-cert/Cargo.toml index f2389671..781bacbe 100644 --- a/icx-cert/Cargo.toml +++ b/icx-cert/Cargo.toml @@ -19,7 +19,7 @@ include = ["src", "Cargo.toml", "../LICENSE", "README.md"] [dependencies] anyhow = "1.0" base64 = "0.13" -clap = { version = "3.1.8", features = ["derive", "cargo"] } +clap = { workspace = true, features = ["derive", "cargo", "color"] } hex = { workspace = true } ic-certification = { workspace = true } leb128 = "0.2.4" diff --git a/icx-cert/src/main.rs b/icx-cert/src/main.rs index d0464433..54104a17 100644 --- a/icx-cert/src/main.rs +++ b/icx-cert/src/main.rs @@ -4,7 +4,7 @@ use clap::{crate_authors, crate_version, Parser}; mod pprint; #[derive(Parser)] -#[clap( +#[command( version = crate_version!(), author = crate_authors!(), )] @@ -15,12 +15,7 @@ enum Command { url: String, /// Specifies one or more encodings to accept. - #[clap( - long, - multiple_occurrences(true), - multiple_values(true), - number_of_values(1) - )] + #[arg(long)] accept_encoding: Option>, }, } @@ -33,3 +28,14 @@ fn main() -> Result<()> { } => pprint::pprint(url, accept_encoding), } } + +#[cfg(test)] +mod tests { + use super::Command; + use clap::CommandFactory; + + #[test] + fn valid_command() { + Command::command().debug_assert(); + } +} diff --git a/icx/Cargo.toml b/icx/Cargo.toml index e207a64c..d0927805 100644 --- a/icx/Cargo.toml +++ b/icx/Cargo.toml @@ -21,7 +21,7 @@ path = "src/main.rs" [dependencies] anyhow = { version = "1.0", features = ["backtrace"] } candid = { workspace = true, features = ["parser"] } -clap = { version = "3.0.14", features = ["derive", "cargo"] } +clap = { workspace = true, features = ["derive", "cargo", "color"] } hex = { workspace = true } humantime = "2.0.1" ic-agent = { workspace = true, default-features = true } diff --git a/icx/src/main.rs b/icx/src/main.rs index eef3b8a3..8cc7d0ab 100644 --- a/icx/src/main.rs +++ b/icx/src/main.rs @@ -5,7 +5,7 @@ use candid::{ types::{Function, Type, TypeInner}, CandidType, Decode, Deserialize, IDLArgs, IDLProg, TypeEnv, }; -use clap::{crate_authors, crate_version, Parser}; +use clap::{crate_authors, crate_version, Parser, ValueEnum}; use ic_agent::{ agent::{self, signed::SignedUpdate}, agent::{ @@ -75,35 +75,32 @@ enum SubCommand { #[derive(Parser)] struct CallOpts { /// The Canister ID to call. - #[clap(parse(try_from_str), required = true)] canister_id: Principal, /// Output the serialization of a message to STDOUT. - #[clap(long)] + #[arg(long)] serialize: bool, /// Path to a candid file to analyze the argument. Otherwise candid will parse the /// argument without type hint. - #[clap(long)] + #[arg(long)] candid: Option, - #[clap(required = true)] method_name: String, /// The type of output (hex or IDL). - #[clap(long, default_value = "idl")] + #[arg(long, value_enum, default_value_t = ArgType::Idl)] arg: ArgType, /// The type of output (hex or IDL). - #[clap(long, default_value = "idl")] + #[arg(long, value_enum, default_value_t = ArgType::Idl)] output: ArgType, /// Argument to send, in Candid textual format. - #[clap()] arg_value: Option, } -#[derive(Parser)] +#[derive(ValueEnum, Clone)] enum ArgType { Idl, Raw, @@ -583,3 +580,14 @@ async fn main() -> Result<()> { Ok(()) } + +#[cfg(test)] +mod tests { + use crate::Opts; + use clap::CommandFactory; + + #[test] + fn valid_command() { + Opts::command().debug_assert(); + } +}