Skip to content

Commit

Permalink
Migrate from structopt to clap derive (use-ink#457)
Browse files Browse the repository at this point in the history
* Migrate from structopt to clap derive

* Add missing clap env feature

* Fmt
  • Loading branch information
ascjones authored Mar 11, 2022
1 parent 10640bc commit 191b588
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 160 deletions.
112 changes: 38 additions & 74 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE", "build.rs", "tem
[dependencies]
env_logger = "0.9.0"
anyhow = "1.0.56"
structopt = "0.3.26"
clap = { version = "3.1.6", features = ["derive", "env"] }
log = "0.4.14"
heck = "0.4.0"
zip = { version = "0.5.13", default-features = false }
Expand Down
33 changes: 16 additions & 17 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use std::{
process::Command,
str,
};
use structopt::StructOpt;

/// This is the maximum number of pages available for a contract to allocate.
const MAX_MEMORY_PAGES: u32 = 16;
Expand All @@ -57,39 +56,39 @@ pub(crate) struct ExecuteArgs {
/// Executes build of the smart contract which produces a Wasm binary that is ready for deploying.
///
/// It does so by invoking `cargo build` and then post processing the final binary.
#[derive(Debug, StructOpt)]
#[structopt(name = "build")]
#[derive(Debug, clap::Args)]
#[clap(name = "build")]
pub struct BuildCommand {
/// Path to the `Cargo.toml` of the contract to build
#[structopt(long, parse(from_os_str))]
#[clap(long, parse(from_os_str))]
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.
#[structopt(long = "--release")]
#[clap(long = "--release")]
build_release: bool,
/// Build offline
#[structopt(long = "--offline")]
#[clap(long = "--offline")]
build_offline: bool,
/// Which build artifacts to generate.
///
/// - `all`: Generate the Wasm, the metadata and a bundled `<name>.contract` file.
///
/// - `code-only`: Only the Wasm is created, generation of metadata and a bundled
/// `<name>.contract` file is skipped.
#[structopt(
#[clap(
long = "generate",
default_value = "all",
value_name = "all | code-only",
verbatim_doc_comment
)]
build_artifact: BuildArtifacts,
#[structopt(flatten)]
#[clap(flatten)]
verbosity: VerbosityFlags,
#[structopt(flatten)]
#[clap(flatten)]
unstable_options: UnstableOptions,
/// Number of optimization passes, passed as an argument to `wasm-opt`.
///
Expand All @@ -113,16 +112,16 @@ pub struct BuildCommand {
/// - It is possible to define the number of optimization passes in the
/// `[package.metadata.contract]` of your `Cargo.toml` as e.g. `optimization-passes = "3"`.
/// The CLI argument always takes precedence over the profile value.
#[structopt(long)]
#[clap(long)]
optimization_passes: Option<OptimizationPasses>,
/// Do not remove symbols (Wasm name section) when optimizing.
///
/// This is useful if one wants to analyze or debug the optimized binary.
#[structopt(long)]
#[clap(long)]
keep_debug_symbols: bool,

/// Export the build output in JSON format.
#[structopt(long, conflicts_with = "verbose")]
#[clap(long, conflicts_with = "verbose")]
output_json: bool,
}

Expand Down Expand Up @@ -184,15 +183,15 @@ impl BuildCommand {
}
}

#[derive(Debug, StructOpt)]
#[structopt(name = "check")]
#[derive(Debug, clap::Args)]
#[clap(name = "check")]
pub struct CheckCommand {
/// Path to the `Cargo.toml` of the contract to build
#[structopt(long, parse(from_os_str))]
#[clap(long, parse(from_os_str))]
manifest_path: Option<PathBuf>,
#[structopt(flatten)]
#[clap(flatten)]
verbosity: VerbosityFlags,
#[structopt(flatten)]
#[clap(flatten)]
unstable_options: UnstableOptions,
}

Expand Down
17 changes: 8 additions & 9 deletions src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,29 @@ use jsonrpsee::{core::client::ClientT, rpc_params, ws_client::WsClientBuilder};
use serde::Serialize;
use sp_core::Bytes;
use std::fmt::Debug;
use structopt::StructOpt;
use subxt::{rpc::NumberOrHex, ClientBuilder, Config, DefaultConfig, Signer};

type ContractExecResult = pallet_contracts_primitives::ContractExecResult<Balance>;

#[derive(Debug, StructOpt)]
#[structopt(name = "call", about = "Call a contract")]
#[derive(Debug, clap::Args)]
#[clap(name = "call", about = "Call a contract")]
pub struct CallCommand {
/// The address of the the contract to call.
#[structopt(name = "contract", long, env = "CONTRACT")]
#[clap(name = "contract", long, env = "CONTRACT")]
contract: <DefaultConfig as Config>::AccountId,
/// The name of the contract message to call.
#[structopt(long, short)]
#[clap(long, short)]
message: String,
/// The arguments of the contract message to call.
#[structopt(long)]
#[clap(long)]
args: Vec<String>,
#[structopt(flatten)]
#[clap(flatten)]
extrinsic_opts: ExtrinsicOpts,
/// Maximum amount of gas to be used for this command.
#[structopt(name = "gas", long, default_value = "50000000000")]
#[clap(name = "gas", long, default_value = "50000000000")]
gas_limit: u64,
/// The value to be transferred as part of the call.
#[structopt(name = "value", long, parse(try_from_str = parse_balance), default_value = "0")]
#[clap(name = "value", long, parse(try_from_str = parse_balance), default_value = "0")]
value: Balance,
}

Expand Down
Loading

0 comments on commit 191b588

Please sign in to comment.