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
@@ -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,
},
}