use clap3 instead of structopt (#10632)

* use clap3 instead of structopt

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* format

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* update ss58-registry and revert some nits

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix clippy and doc

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* update clap to 3.0.7

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Apply review suggestions

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* remove useless option long name

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* cargo fmt

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
Qinxuan Chen
2022-01-25 00:28:46 +08:00
committed by GitHub
parent d1ff02d31e
commit e327b734bc
66 changed files with 660 additions and 768 deletions
@@ -25,7 +25,7 @@ sp-keystore = { version = "0.10.0", path = "../../../primitives/keystore" }
sp-runtime = { version = "4.1.0-dev", path = "../../../primitives/runtime" }
sp-state-machine = { version = "0.10.0", path = "../../../primitives/state-machine" }
codec = { version = "2.0.0", package = "parity-scale-codec" }
structopt = "0.3.25"
clap = { version = "3.0", features = ["derive"] }
chrono = "0.4"
serde = "1.0.132"
handlebars = "4.1.6"
@@ -28,124 +28,119 @@ fn parse_pallet_name(pallet: &str) -> String {
}
/// The `benchmark` command used to benchmark FRAME Pallets.
#[derive(Debug, structopt::StructOpt)]
#[derive(Debug, clap::Parser)]
pub struct BenchmarkCmd {
/// Select a FRAME Pallet to benchmark, or `*` for all (in which case `extrinsic` must be `*`).
#[structopt(short, long, parse(from_str = parse_pallet_name), required_unless = "list")]
#[clap(short, long, parse(from_str = parse_pallet_name), required_unless_present = "list")]
pub pallet: Option<String>,
/// Select an extrinsic inside the pallet to benchmark, or `*` for all.
#[structopt(short, long, required_unless = "list")]
#[clap(short, long, required_unless_present = "list")]
pub extrinsic: Option<String>,
/// Select how many samples we should take across the variable components.
#[structopt(short, long, default_value = "1")]
#[clap(short, long, default_value = "1")]
pub steps: u32,
/// Indicates lowest values for each of the component ranges.
#[structopt(long = "low", use_delimiter = true)]
#[clap(long = "low", use_delimiter = true)]
pub lowest_range_values: Vec<u32>,
/// Indicates highest values for each of the component ranges.
#[structopt(long = "high", use_delimiter = true)]
#[clap(long = "high", use_delimiter = true)]
pub highest_range_values: Vec<u32>,
/// Select how many repetitions of this benchmark should run from within the wasm.
#[structopt(short, long, default_value = "1")]
#[clap(short, long, default_value = "1")]
pub repeat: u32,
/// Select how many repetitions of this benchmark should run from the client.
///
/// NOTE: Using this alone may give slower results, but will afford you maximum Wasm memory.
#[structopt(long, default_value = "1")]
#[clap(long, default_value = "1")]
pub external_repeat: u32,
/// Print the raw results.
#[structopt(long = "raw")]
#[clap(long = "raw")]
pub raw_data: bool,
/// Don't print the median-slopes linear regression analysis.
#[structopt(long)]
#[clap(long)]
pub no_median_slopes: bool,
/// Don't print the min-squares linear regression analysis.
#[structopt(long)]
#[clap(long)]
pub no_min_squares: bool,
/// Output the benchmarks to a Rust file at the given path.
#[structopt(long)]
#[clap(long)]
pub output: Option<std::path::PathBuf>,
/// Add a header file to your outputted benchmarks
#[structopt(long)]
#[clap(long)]
pub header: Option<std::path::PathBuf>,
/// Path to Handlebars template file used for outputting benchmark results. (Optional)
#[structopt(long)]
#[clap(long)]
pub template: Option<std::path::PathBuf>,
/// Which analysis function to use when outputting benchmarks:
/// * min-squares (default)
/// * median-slopes
/// * max (max of min squares and median slopes for each value)
#[structopt(long)]
#[clap(long)]
pub output_analysis: Option<String>,
/// Set the heap pages while running benchmarks. If not set, the default value from the client
/// is used.
#[structopt(long)]
#[clap(long)]
pub heap_pages: Option<u64>,
/// Disable verification logic when running benchmarks.
#[structopt(long)]
#[clap(long)]
pub no_verify: bool,
/// Display and run extra benchmarks that would otherwise not be needed for weight
/// construction.
#[structopt(long)]
#[clap(long)]
pub extra: bool,
/// Estimate PoV size.
#[structopt(long)]
#[clap(long)]
pub record_proof: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: sc_cli::SharedParams,
/// The execution strategy that should be used for benchmarks
#[structopt(
long = "execution",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true)]
pub execution: Option<ExecutionStrategy>,
/// Method for executing Wasm runtime code.
#[structopt(
#[clap(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::variants(),
case_insensitive = true,
possible_values = WasmExecutionMethod::variants(),
ignore_case = true,
default_value = "compiled"
)]
pub wasm_method: WasmExecutionMethod,
/// Limit the memory the database cache can use.
#[structopt(long = "db-cache", value_name = "MiB", default_value = "1024")]
#[clap(long = "db-cache", value_name = "MiB", default_value = "1024")]
pub database_cache_size: u32,
/// List the benchmarks that match your query rather than running them.
///
/// When nothing is provided, we list all benchmarks.
#[structopt(long)]
#[clap(long)]
pub list: bool,
/// If enabled, the storage info is not displayed in the output next to the analysis.
///
/// This is independent of the storage info appearing in the *output file*. Use a Handlebar
/// template for that purpose.
#[structopt(long)]
#[clap(long)]
pub no_storage_info: bool,
}
@@ -11,10 +11,11 @@ documentation = "https://docs.rs/substrate-frame-cli"
readme = "README.md"
[dependencies]
clap = { version = "3.0", features = ["derive"] }
sp-core = { version = "4.1.0-dev", path = "../../../primitives/core" }
sc-cli = { version = "0.10.0-dev", path = "../../../client/cli" }
sp-runtime = { version = "4.1.0-dev", path = "../../../primitives/runtime" }
structopt = "0.3.25"
frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
frame-support = { version = "4.0.0-dev", path = "../../../frame/support" }
@@ -17,6 +17,7 @@
//! Implementation of the `palletid` subcommand
use clap::Parser;
use frame_support::PalletId;
use sc_cli::{
utils::print_from_uri, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams,
@@ -24,35 +25,34 @@ use sc_cli::{
};
use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec};
use sp_runtime::traits::AccountIdConversion;
use structopt::StructOpt;
/// The `palletid` command
#[derive(Debug, StructOpt)]
#[structopt(name = "palletid", about = "Inspect a module ID address")]
#[derive(Debug, Parser)]
#[clap(name = "palletid", about = "Inspect a module ID address")]
pub struct PalletIdCmd {
/// The module ID used to derive the account
id: String,
/// network address format
#[structopt(
#[clap(
long,
value_name = "NETWORK",
possible_values = &Ss58AddressFormat::all_names()[..],
parse(try_from_str = Ss58AddressFormat::try_from),
case_insensitive = true,
ignore_case = true,
)]
pub network: Option<Ss58AddressFormat>,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub output_scheme: OutputTypeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub crypto_scheme: CryptoSchemeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub keystore_params: KeystoreParams,
}
@@ -23,4 +23,3 @@ sp-io = { version = "4.0.0", path = "../../../primitives/io" }
chrono = { version = "0.4.19" }
git2 = { version = "0.13.25", default-features = false }
num-format = { version = "0.4.0" }
structopt = "0.3.25"
@@ -14,4 +14,4 @@ node-runtime = { version = "3.0.0-dev", path = "../../../../bin/node/runtime" }
generate-bags = { version = "4.0.0-dev", path = "../" }
# third-party
structopt = "0.3.25"
clap = { version = "3.0", features = ["derive"] }
@@ -17,30 +17,31 @@
//! Make the set of bag thresholds to be used with pallet-bags-list.
use clap::Parser;
use generate_bags::generate_thresholds;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
// #[clap(author, version, about)]
struct Opt {
/// How many bags to generate.
#[structopt(long, default_value = "200")]
#[clap(long, default_value = "200")]
n_bags: usize,
/// Where to write the output.
output: PathBuf,
/// The total issuance of the currency used to create `VoteWeight`.
#[structopt(short, long)]
#[clap(short, long)]
total_issuance: u128,
/// The minimum account balance (i.e. existential deposit) for the currency used to create
/// `VoteWeight`.
#[structopt(short, long)]
#[clap(short, long)]
minimum_balance: u128,
}
fn main() -> Result<(), std::io::Error> {
let Opt { n_bags, output, total_issuance, minimum_balance } = Opt::from_args();
let Opt { n_bags, output, total_issuance, minimum_balance } = Opt::parse();
generate_thresholds::<node_runtime::Runtime>(n_bags, &output, total_issuance, minimum_balance)
}
@@ -13,10 +13,11 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
clap = { version = "3.0", features = ["derive"] }
log = "0.4.8"
parity-scale-codec = { version = "2.3.1" }
serde = "1.0.132"
structopt = "0.3.25"
zstd = "0.9.0"
sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../../client/service" }
sc-cli = { version = "0.10.0-dev", path = "../../../../client/cli" }
@@ -31,6 +32,4 @@ sp-externalities = { version = "0.10.0", path = "../../../../primitives/external
sp-version = { version = "4.0.0-dev", path = "../../../../primitives/version" }
remote-externalities = { version = "0.10.0-dev", path = "../../remote-externalities" }
jsonrpsee = { version = "0.4.1", default-features = false, features = ["ws-client"]}
zstd = "0.9.0"
jsonrpsee = { version = "0.4.1", default-features = false, features = ["ws-client"] }
@@ -26,25 +26,25 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use std::{fmt::Debug, str::FromStr};
/// Configurations of the [`Command::ExecuteBlock`].
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Parser)]
pub struct ExecuteBlockCmd {
/// Overwrite the wasm code in state or not.
#[structopt(long)]
#[clap(long)]
overwrite_wasm_code: bool,
/// If set, then the state root check is disabled by the virtue of calling into
/// `TryRuntime_execute_block_no_check` instead of
/// `Core_execute_block`.
#[structopt(long)]
#[clap(long)]
no_check: bool,
/// The block hash at which to fetch the block.
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::at` is. Only use this (with care) when combined with a snapshot.
#[structopt(
#[clap(
long,
multiple = false,
multiple_values = false,
parse(try_from_str = crate::parse::hash)
)]
block_at: Option<String>,
@@ -53,9 +53,9 @@ pub struct ExecuteBlockCmd {
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::uri` is. Only use this (with care) when combined with a snapshot.
#[structopt(
#[clap(
long,
multiple = false,
multiple_values = false,
parse(try_from_str = crate::parse::url)
)]
block_ws_uri: Option<String>,
@@ -65,7 +65,7 @@ pub struct ExecuteBlockCmd {
/// For this command only, if the `live` is used, then state of the parent block is fetched.
///
/// If `block_at` is provided, then the [`State::Live::at`] is being ignored.
#[structopt(subcommand)]
#[clap(subcommand)]
state: State,
}
@@ -35,14 +35,10 @@ const SUB: &'static str = "chain_subscribeFinalizedHeads";
const UN_SUB: &'static str = "chain_unsubscribeFinalizedHeads";
/// Configurations of the [`Command::FollowChain`].
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Parser)]
pub struct FollowChainCmd {
/// The url to connect to.
#[structopt(
short,
long,
parse(try_from_str = parse::url),
)]
#[clap(short, long, parse(try_from_str = parse::url))]
uri: String,
}
@@ -28,19 +28,19 @@ use sp_runtime::traits::{Block as BlockT, Header, NumberFor};
use std::{fmt::Debug, str::FromStr};
/// Configurations of the [`Command::OffchainWorker`].
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Parser)]
pub struct OffchainWorkerCmd {
/// Overwrite the wasm code in state or not.
#[structopt(long)]
#[clap(long)]
overwrite_wasm_code: bool,
/// The block hash at which to fetch the header.
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::at` is. Only use this (with care) when combined with a snapshot.
#[structopt(
#[clap(
long,
multiple = false,
multiple_values = false,
parse(try_from_str = parse::hash)
)]
header_at: Option<String>,
@@ -49,15 +49,15 @@ pub struct OffchainWorkerCmd {
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::uri` is. Only use this (with care) when combined with a snapshot.
#[structopt(
#[clap(
long,
multiple = false,
multiple_values = false,
parse(try_from_str = parse::url)
)]
header_ws_uri: Option<String>,
/// The state type to use.
#[structopt(subcommand)]
#[clap(subcommand)]
pub state: State,
}
@@ -28,10 +28,10 @@ use crate::{
};
/// Configurations of the [`Command::OnRuntimeUpgrade`].
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Parser)]
pub struct OnRuntimeUpgradeCmd {
/// The state type to use.
#[structopt(subcommand)]
#[clap(subcommand)]
pub state: State,
}
@@ -293,7 +293,7 @@ pub(crate) mod parse;
pub(crate) const LOG_TARGET: &'static str = "try-runtime::cli";
/// Possible commands of `try-runtime`.
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Subcommand)]
pub enum Command {
/// Execute the migrations of the "local runtime".
///
@@ -373,70 +373,64 @@ pub enum Command {
}
/// Shared parameters of the `try-runtime` commands
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Parser)]
pub struct SharedParams {
/// Shared parameters of substrate cli.
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: sc_cli::SharedParams,
/// The execution strategy that should be used.
#[structopt(
long = "execution",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
default_value = "Wasm",
)]
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true, default_value = "Wasm")]
pub execution: ExecutionStrategy,
/// Type of wasm execution used.
#[structopt(
#[clap(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::variants(),
case_insensitive = true,
possible_values = WasmExecutionMethod::variants(),
ignore_case = true,
default_value = "Compiled"
)]
pub wasm_method: WasmExecutionMethod,
/// The number of 64KB pages to allocate for Wasm execution. Defaults to
/// [`sc_service::Configuration.default_heap_pages`].
#[structopt(long)]
#[clap(long)]
pub heap_pages: Option<u64>,
/// When enabled, the spec name check will not panic, and instead only show a warning.
#[structopt(long)]
#[clap(long)]
pub no_spec_name_check: bool,
}
/// Our `try-runtime` command.
///
/// See [`Command`] for more info.
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Parser)]
pub struct TryRuntimeCmd {
#[structopt(flatten)]
#[clap(flatten)]
pub shared: SharedParams,
#[structopt(subcommand)]
#[clap(subcommand)]
pub command: Command,
}
/// The source of runtime *state* to use.
#[derive(Debug, Clone, structopt::StructOpt)]
#[derive(Debug, Clone, clap::Subcommand)]
pub enum State {
/// Use a state snapshot as the source of runtime state.
///
/// This can be crated by passing a value to [`State::Live::snapshot_path`].
Snap {
#[structopt(short, long)]
#[clap(short, long)]
snapshot_path: PathBuf,
},
/// Use a live chain as the source of runtime state.
Live {
/// The url to connect to.
#[structopt(
#[clap(
short,
long,
parse(try_from_str = parse::url),
@@ -447,20 +441,20 @@ pub enum State {
///
/// If non provided, then the latest finalized head is used. This is particularly useful
/// for [`Command::OnRuntimeUpgrade`].
#[structopt(
#[clap(
short,
long,
multiple = false,
multiple_values = false,
parse(try_from_str = parse::hash),
)]
at: Option<String>,
/// An optional state snapshot file to WRITE to. Not written if set to `None`.
#[structopt(short, long)]
#[clap(short, long)]
snapshot_path: Option<PathBuf>,
/// The pallets to scrape. If empty, entire chain state will be scraped.
#[structopt(short, long, require_delimiter = true)]
#[clap(short, long, require_delimiter = true)]
pallets: Option<Vec<String>>,
/// Fetch the child-keys as well.
@@ -468,7 +462,7 @@ pub enum State {
/// Default is `false`, if specific `pallets` are specified, true otherwise. In other
/// words, if you scrape the whole state the child tree data is included out of the box.
/// Otherwise, it must be enabled explicitly using this flag.
#[structopt(long, require_delimiter = true)]
#[clap(long, require_delimiter = true)]
child_tree: bool,
},
}