Skip to content

Commit

Permalink
Upgrade clap to version 4 (use-ink#761)
Browse files Browse the repository at this point in the history
* Upgrade clap to version 4

* Fix long arg names
  • Loading branch information
ascjones authored Sep 30, 2022
1 parent 956d11e commit 894993c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 41 deletions.
24 changes: 8 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cargo-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions crates/cargo-contract/src/cmd/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ 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<PathBuf>,
/// By default the contract is compiled with debug functionality
/// included. This enables the contract to output debug messages,
/// but increases the contract size and the amount of gas used.
///
/// 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.
///
Expand All @@ -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,
Expand Down Expand Up @@ -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<PathBuf>,
#[clap(flatten)]
verbosity: VerbosityFlags,
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-contract/src/cmd/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[clap(flatten)]
extrinsic_opts: ExtrinsicOpts,
Expand All @@ -80,7 +80,7 @@ pub struct CallCommand {
#[clap(name = "gas", long)]
gas_limit: Option<u64>,
/// 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")]
Expand Down
10 changes: 5 additions & 5 deletions crates/cargo-contract/src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,31 @@ pub struct InstantiateCommand {
/// Path to Wasm contract code, defaults to `./target/ink/<name>.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<PathBuf>,
/// 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<<DefaultConfig as Config>::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<String>,
#[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.
#[clap(name = "gas", long)]
gas_limit: Option<u64>,
/// 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<Bytes>,
/// Export the instantiate output in JSON format.
#[clap(long, conflicts_with = "verbose")]
Expand Down
6 changes: 3 additions & 3 deletions crates/cargo-contract/src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ type Client = OnlineClient<DefaultConfig>;
#[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<PathBuf>,
/// Websockets url of a substrate node.
#[clap(
name = "url",
long,
parse(try_from_str),
value_parser,
default_value = "ws://localhost:9944"
)]
url: url::Url,
Expand All @@ -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<Balance>,
/// Before submitting a transaction, do not dry-run it via RPC first.
#[clap(long)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>.wasm`.
#[clap(parse(from_os_str))]
#[clap(value_parser)]
wasm_path: Option<PathBuf>,
#[clap(flatten)]
extrinsic_opts: ExtrinsicOpts,
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
#[clap(flatten)]
verbosity: VerbosityFlags,
Expand Down
7 changes: 3 additions & 4 deletions crates/cargo-contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use anyhow::{
Result,
};
use clap::{
AppSettings,
Args,
Parser,
Subcommand,
Expand All @@ -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),
}

Expand Down Expand Up @@ -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 `<name>.contract` file
Expand Down Expand Up @@ -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<PathBuf>,
},
/// Compiles the contract, generates metadata, bundles both together in a `<name>.contract` file
Expand Down

0 comments on commit 894993c

Please sign in to comment.