From 894993cf08269254401a31efced7a932b34cd832 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 30 Sep 2022 14:50:33 +0100 Subject: [PATCH] Upgrade clap to version 4 (#761) * Upgrade clap to version 4 * Fix long arg names --- Cargo.lock | 24 +++++++------------ crates/cargo-contract/Cargo.toml | 2 +- crates/cargo-contract/src/cmd/build/mod.rs | 12 +++++----- crates/cargo-contract/src/cmd/decode.rs | 4 ++-- .../cargo-contract/src/cmd/extrinsics/call.rs | 4 ++-- .../src/cmd/extrinsics/instantiate.rs | 10 ++++---- .../cargo-contract/src/cmd/extrinsics/mod.rs | 6 ++--- .../src/cmd/extrinsics/upload.rs | 2 +- crates/cargo-contract/src/cmd/test.rs | 2 +- crates/cargo-contract/src/main.rs | 7 +++--- 10 files changed, 32 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dacaae8b..4f401f72b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -553,26 +553,24 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.22" +version = "4.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "7f78ad8e84aa8e8aa3e821857be40eb4b925ff232de430d4dd2ae6aa058cbd92" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "ca689d7434ce44517a12a89456b2be4d1ea1cafcd8f581978c03d45f5a5c12a7" dependencies = [ "heck", "proc-macro-error", @@ -583,9 +581,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5538cd660450ebeb4234cfecf8f2284b844ffc4c50531e66d584ad5b91293613" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -2351,9 +2349,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] @@ -3467,12 +3465,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" -[[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - [[package]] name = "thiserror" version = "1.0.31" diff --git a/crates/cargo-contract/Cargo.toml b/crates/cargo-contract/Cargo.toml index 187ac3da2..03da9ba03 100644 --- a/crates/cargo-contract/Cargo.toml +++ b/crates/cargo-contract/Cargo.toml @@ -19,7 +19,7 @@ include = [ [dependencies] anyhow = "1.0.65" -clap = { version = "3.2.22", features = ["derive", "env"] } +clap = { version = "4.0.4", features = ["derive", "env"] } tracing = "0.1.36" tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } heck = "0.4.0" diff --git a/crates/cargo-contract/src/cmd/build/mod.rs b/crates/cargo-contract/src/cmd/build/mod.rs index 76501a39f..ee6863462 100644 --- a/crates/cargo-contract/src/cmd/build/mod.rs +++ b/crates/cargo-contract/src/cmd/build/mod.rs @@ -90,7 +90,7 @@ pub(crate) struct ExecuteArgs { #[clap(name = "build")] pub struct BuildCommand { /// Path to the `Cargo.toml` of the contract to build - #[clap(long, parse(from_os_str))] + #[clap(long, value_parser)] manifest_path: Option, /// By default the contract is compiled with debug functionality /// included. This enables the contract to output debug messages, @@ -98,13 +98,13 @@ pub struct BuildCommand { /// /// A production contract should always be build in `release` mode! /// Then no debug functionality is compiled into the contract. - #[clap(long = "--release")] + #[clap(long = "release")] build_release: bool, /// Build offline - #[clap(long = "--offline")] + #[clap(long = "offline")] build_offline: bool, /// Skips linting checks during the build process - #[clap(long = "--skip-linting")] + #[clap(long)] skip_linting: bool, /// Which build artifacts to generate. /// @@ -115,7 +115,7 @@ pub struct BuildCommand { /// /// - `check-only`: No artifacts produced: runs the `cargo check` command for the Wasm target, /// only checks for compilation errors. - #[clap(long = "generate", arg_enum, default_value = "all")] + #[clap(long = "generate", value_enum, default_value = "all")] build_artifact: BuildArtifacts, #[clap(flatten)] verbosity: VerbosityFlags, @@ -223,7 +223,7 @@ impl BuildCommand { #[clap(name = "check")] pub struct CheckCommand { /// Path to the `Cargo.toml` of the contract to build - #[clap(long, parse(from_os_str))] + #[clap(long, value_parser)] manifest_path: Option, #[clap(flatten)] verbosity: VerbosityFlags, diff --git a/crates/cargo-contract/src/cmd/decode.rs b/crates/cargo-contract/src/cmd/decode.rs index 4495f008d..1b8a68ddd 100644 --- a/crates/cargo-contract/src/cmd/decode.rs +++ b/crates/cargo-contract/src/cmd/decode.rs @@ -33,14 +33,14 @@ use transcode::ContractMessageTranscoder; )] pub struct DecodeCommand { /// The type of data to encode. - #[clap(arg_enum, short, long)] + #[clap(value_enum, short, long)] r#type: DataType, /// The data to decode; this has to be a hex value starting with `0x`. #[clap(short, long)] data: String, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ArgEnum)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)] enum DataType { Event, Message, diff --git a/crates/cargo-contract/src/cmd/extrinsics/call.rs b/crates/cargo-contract/src/cmd/extrinsics/call.rs index ac0d26caa..e5f5c32ec 100644 --- a/crates/cargo-contract/src/cmd/extrinsics/call.rs +++ b/crates/cargo-contract/src/cmd/extrinsics/call.rs @@ -71,7 +71,7 @@ pub struct CallCommand { #[clap(long, short)] message: String, /// The arguments of the contract message to call. - #[clap(long, multiple_values = true)] + #[clap(long, num_args = 0..)] args: Vec, #[clap(flatten)] extrinsic_opts: ExtrinsicOpts, @@ -80,7 +80,7 @@ pub struct CallCommand { #[clap(name = "gas", long)] gas_limit: Option, /// The value to be transferred as part of the call. - #[clap(name = "value", long, parse(try_from_str = parse_balance), default_value = "0")] + #[clap(name = "value", long, value_parser = parse_balance, default_value = "0")] value: Balance, /// Export the call output in JSON format. #[clap(long, conflicts_with = "verbose")] diff --git a/crates/cargo-contract/src/cmd/extrinsics/instantiate.rs b/crates/cargo-contract/src/cmd/extrinsics/instantiate.rs index b7c76f202..61f90e955 100644 --- a/crates/cargo-contract/src/cmd/extrinsics/instantiate.rs +++ b/crates/cargo-contract/src/cmd/extrinsics/instantiate.rs @@ -79,23 +79,23 @@ pub struct InstantiateCommand { /// Path to Wasm contract code, defaults to `./target/ink/.wasm`. /// Use to instantiate contracts which have not yet been uploaded. /// If the contract has already been uploaded use `--code-hash` instead. - #[clap(parse(from_os_str))] + #[clap(value_parser)] wasm_path: Option, /// The hash of the smart contract code already uploaded to the chain. /// If the contract has not already been uploaded use `--wasm-path` or run the `upload` command /// first. - #[clap(long, parse(try_from_str = parse_code_hash))] + #[clap(long, value_parser = parse_code_hash)] code_hash: Option<::Hash>, /// The name of the contract constructor to call #[clap(name = "constructor", long, default_value = "new")] constructor: String, /// The constructor arguments, encoded as strings - #[clap(long, multiple_values = true)] + #[clap(long, num_args = 0..)] args: Vec, #[clap(flatten)] extrinsic_opts: ExtrinsicOpts, /// Transfers an initial balance to the instantiated contract - #[clap(name = "value", long, default_value = "0", parse(try_from_str = parse_balance))] + #[clap(name = "value", long, default_value = "0", value_parser = parse_balance)] value: Balance, /// Maximum amount of gas to be used for this command. /// If not specified will perform a dry-run to estimate the gas consumed for the instantiation. @@ -103,7 +103,7 @@ pub struct InstantiateCommand { gas_limit: Option, /// A salt used in the address derivation of the new contract. Use to create multiple instances /// of the same contract code from the same account. - #[clap(long, parse(try_from_str = parse_hex_bytes))] + #[clap(long, value_parser = parse_hex_bytes)] salt: Option, /// Export the instantiate output in JSON format. #[clap(long, conflicts_with = "verbose")] diff --git a/crates/cargo-contract/src/cmd/extrinsics/mod.rs b/crates/cargo-contract/src/cmd/extrinsics/mod.rs index 1d641d9d5..708e54b7e 100644 --- a/crates/cargo-contract/src/cmd/extrinsics/mod.rs +++ b/crates/cargo-contract/src/cmd/extrinsics/mod.rs @@ -83,13 +83,13 @@ type Client = OnlineClient; #[derive(Clone, Debug, clap::Args)] pub struct ExtrinsicOpts { /// Path to the `Cargo.toml` of the contract. - #[clap(long, parse(from_os_str))] + #[clap(long, value_parser)] manifest_path: Option, /// Websockets url of a substrate node. #[clap( name = "url", long, - parse(try_from_str), + value_parser, default_value = "ws://localhost:9944" )] url: url::Url, @@ -106,7 +106,7 @@ pub struct ExtrinsicOpts { dry_run: bool, /// The maximum amount of balance that can be charged from the caller to pay for the storage /// consumed. - #[clap(long, parse(try_from_str = parse_balance))] + #[clap(long, value_parser = parse_balance)] storage_deposit_limit: Option, /// Before submitting a transaction, do not dry-run it via RPC first. #[clap(long)] diff --git a/crates/cargo-contract/src/cmd/extrinsics/upload.rs b/crates/cargo-contract/src/cmd/extrinsics/upload.rs index 0c667eae5..6dcccf455 100644 --- a/crates/cargo-contract/src/cmd/extrinsics/upload.rs +++ b/crates/cargo-contract/src/cmd/extrinsics/upload.rs @@ -53,7 +53,7 @@ use subxt::{ #[clap(name = "upload", about = "Upload a contract's code")] pub struct UploadCommand { /// Path to Wasm contract code, defaults to `./target/ink/.wasm`. - #[clap(parse(from_os_str))] + #[clap(value_parser)] wasm_path: Option, #[clap(flatten)] extrinsic_opts: ExtrinsicOpts, diff --git a/crates/cargo-contract/src/cmd/test.rs b/crates/cargo-contract/src/cmd/test.rs index 9c6a4c86a..ea363ee01 100644 --- a/crates/cargo-contract/src/cmd/test.rs +++ b/crates/cargo-contract/src/cmd/test.rs @@ -33,7 +33,7 @@ use std::{ #[clap(name = "test")] pub struct TestCommand { /// Path to the `Cargo.toml` of the contract to test. - #[clap(long, parse(from_os_str))] + #[clap(long, value_parser)] manifest_path: Option, #[clap(flatten)] verbosity: VerbosityFlags, diff --git a/crates/cargo-contract/src/main.rs b/crates/cargo-contract/src/main.rs index 9e375d0e9..1cc06b674 100644 --- a/crates/cargo-contract/src/main.rs +++ b/crates/cargo-contract/src/main.rs @@ -56,7 +56,6 @@ use anyhow::{ Result, }; use clap::{ - AppSettings, Args, Parser, Subcommand, @@ -79,7 +78,7 @@ pub(crate) enum Opts { /// Utilities to develop Wasm smart contracts. #[clap(name = "contract")] #[clap(version = env!("CARGO_CONTRACT_CLI_IMPL_VERSION"))] - #[clap(setting = AppSettings::DeriveDisplayOrder)] + #[clap(action = ArgAction::DeriveDisplayOrder)] Contract(ContractArgs), } @@ -241,7 +240,7 @@ impl TryFrom<&UnstableOptions> for UnstableFlags { } /// Describes which artifacts to generate -#[derive(Copy, Clone, Eq, PartialEq, Debug, clap::ArgEnum, serde::Serialize)] +#[derive(Copy, Clone, Eq, PartialEq, Debug, clap::ValueEnum, serde::Serialize)] #[clap(name = "build-artifacts")] pub enum BuildArtifacts { /// Generate the Wasm, the metadata and a bundled `.contract` file @@ -458,7 +457,7 @@ enum Command { /// The name of the newly created smart contract name: String, /// The optional target directory for the contract project - #[clap(short, long, parse(from_os_str))] + #[clap(short, long, value_parser)] target_dir: Option, }, /// Compiles the contract, generates metadata, bundles both together in a `.contract` file