mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 09:17:58 +00:00
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:
@@ -25,6 +25,7 @@ use crate::{
|
||||
},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use regex::Regex;
|
||||
use sc_service::{
|
||||
config::{BasePath, PrometheusConfig, TransactionPoolOptions},
|
||||
@@ -32,26 +33,25 @@ use sc_service::{
|
||||
};
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `run` command used to run a node.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct RunCmd {
|
||||
/// Enable validator mode.
|
||||
///
|
||||
/// The node will be started with the authority role and actively
|
||||
/// participate in any consensus task that it can (e.g. depending on
|
||||
/// availability of local keys).
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub validator: bool,
|
||||
|
||||
/// Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA
|
||||
/// observer.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub no_grandpa: bool,
|
||||
|
||||
/// Experimental: Run in light client mode.
|
||||
#[structopt(long = "light")]
|
||||
#[clap(long)]
|
||||
pub light: bool,
|
||||
|
||||
/// Listen to all RPC interfaces.
|
||||
@@ -60,13 +60,13 @@ pub struct RunCmd {
|
||||
/// proxy server to filter out dangerous methods. More details:
|
||||
/// <https://docs.substrate.io/v3/runtime/custom-rpcs/#public-rpcs>.
|
||||
/// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks.
|
||||
#[structopt(long = "rpc-external")]
|
||||
#[clap(long)]
|
||||
pub rpc_external: bool,
|
||||
|
||||
/// Listen to all RPC interfaces.
|
||||
///
|
||||
/// Same as `--rpc-external`.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub unsafe_rpc_external: bool,
|
||||
|
||||
/// RPC methods to expose.
|
||||
@@ -75,11 +75,11 @@ pub struct RunCmd {
|
||||
/// - `Safe`: Exposes only a safe subset of RPC methods, denying unsafe RPC methods.
|
||||
/// - `Auto`: Acts as `Safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is
|
||||
/// passed, otherwise acts as `Unsafe`.
|
||||
#[structopt(
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "METHOD SET",
|
||||
possible_values = &RpcMethods::variants(),
|
||||
case_insensitive = true,
|
||||
arg_enum,
|
||||
ignore_case = true,
|
||||
default_value = "Auto",
|
||||
verbatim_doc_comment
|
||||
)]
|
||||
@@ -91,44 +91,44 @@ pub struct RunCmd {
|
||||
/// proxy server to filter out dangerous methods. More details:
|
||||
/// <https://docs.substrate.io/v3/runtime/custom-rpcs/#public-rpcs>.
|
||||
/// Use `--unsafe-ws-external` to suppress the warning if you understand the risks.
|
||||
#[structopt(long = "ws-external")]
|
||||
#[clap(long)]
|
||||
pub ws_external: bool,
|
||||
|
||||
/// Listen to all Websocket interfaces.
|
||||
///
|
||||
/// Same as `--ws-external` but doesn't warn you about it.
|
||||
#[structopt(long = "unsafe-ws-external")]
|
||||
#[clap(long)]
|
||||
pub unsafe_ws_external: bool,
|
||||
|
||||
/// Set the the maximum RPC payload size for both requests and responses (both http and ws), in
|
||||
/// megabytes. Default is 15MiB.
|
||||
#[structopt(long = "rpc-max-payload")]
|
||||
#[clap(long)]
|
||||
pub rpc_max_payload: Option<usize>,
|
||||
|
||||
/// Expose Prometheus exporter on all interfaces.
|
||||
///
|
||||
/// Default is local.
|
||||
#[structopt(long = "prometheus-external")]
|
||||
#[clap(long)]
|
||||
pub prometheus_external: bool,
|
||||
|
||||
/// Specify IPC RPC server path
|
||||
#[structopt(long = "ipc-path", value_name = "PATH")]
|
||||
#[clap(long, value_name = "PATH")]
|
||||
pub ipc_path: Option<String>,
|
||||
|
||||
/// Specify HTTP RPC server TCP port.
|
||||
#[structopt(long = "rpc-port", value_name = "PORT")]
|
||||
#[clap(long, value_name = "PORT")]
|
||||
pub rpc_port: Option<u16>,
|
||||
|
||||
/// Specify WebSockets RPC server TCP port.
|
||||
#[structopt(long = "ws-port", value_name = "PORT")]
|
||||
#[clap(long, value_name = "PORT")]
|
||||
pub ws_port: Option<u16>,
|
||||
|
||||
/// Maximum number of WS RPC server connections.
|
||||
#[structopt(long = "ws-max-connections", value_name = "COUNT")]
|
||||
#[clap(long, value_name = "COUNT")]
|
||||
pub ws_max_connections: Option<usize>,
|
||||
|
||||
/// Set the the maximum WebSocket output buffer size in MiB. Default is 16.
|
||||
#[structopt(long = "ws-max-out-buffer-capacity")]
|
||||
#[clap(long)]
|
||||
pub ws_max_out_buffer_capacity: Option<usize>,
|
||||
|
||||
/// Specify browser Origins allowed to access the HTTP & WS RPC servers.
|
||||
@@ -137,29 +137,29 @@ pub struct RunCmd {
|
||||
/// value). Value of `all` will disable origin validation. Default is to
|
||||
/// allow localhost and <https://polkadot.js.org> origins. When running in
|
||||
/// --dev mode the default is to allow all origins.
|
||||
#[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))]
|
||||
#[clap(long, value_name = "ORIGINS", parse(from_str = parse_cors))]
|
||||
pub rpc_cors: Option<Cors>,
|
||||
|
||||
/// Specify Prometheus exporter TCP Port.
|
||||
#[structopt(long = "prometheus-port", value_name = "PORT")]
|
||||
#[clap(long, value_name = "PORT")]
|
||||
pub prometheus_port: Option<u16>,
|
||||
|
||||
/// Do not expose a Prometheus exporter endpoint.
|
||||
///
|
||||
/// Prometheus metric endpoint is enabled by default.
|
||||
#[structopt(long = "no-prometheus")]
|
||||
#[clap(long)]
|
||||
pub no_prometheus: bool,
|
||||
|
||||
/// The human-readable name for this node.
|
||||
///
|
||||
/// The node name will be reported to the telemetry server, if enabled.
|
||||
#[structopt(long = "name", value_name = "NAME")]
|
||||
#[clap(long, value_name = "NAME")]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// Disable connecting to the Substrate telemetry server.
|
||||
///
|
||||
/// Telemetry is on by default on global chains.
|
||||
#[structopt(long = "no-telemetry")]
|
||||
#[clap(long)]
|
||||
pub no_telemetry: bool,
|
||||
|
||||
/// The URL of the telemetry server to connect to.
|
||||
@@ -168,78 +168,78 @@ pub struct RunCmd {
|
||||
/// telemetry endpoints. Verbosity levels range from 0-9, with 0 denoting
|
||||
/// the least verbosity.
|
||||
/// Expected format is 'URL VERBOSITY', e.g. `--telemetry-url 'wss://foo/bar 0'`.
|
||||
#[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))]
|
||||
#[clap(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))]
|
||||
pub telemetry_endpoints: Vec<(String, u8)>,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub offchain_worker_params: OffchainWorkerParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub import_params: ImportParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub network_params: NetworkParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub pool_config: TransactionPoolParams,
|
||||
|
||||
/// Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
pub alice: bool,
|
||||
|
||||
/// Shortcut for `--name Bob --validator` with session keys for `Bob` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
pub bob: bool,
|
||||
|
||||
/// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to
|
||||
/// keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])]
|
||||
pub charlie: bool,
|
||||
|
||||
/// Shortcut for `--name Dave --validator` with session keys for `Dave` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])]
|
||||
pub dave: bool,
|
||||
|
||||
/// Shortcut for `--name Eve --validator` with session keys for `Eve` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])]
|
||||
pub eve: bool,
|
||||
|
||||
/// Shortcut for `--name Ferdie --validator` with session keys for `Ferdie` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])]
|
||||
pub ferdie: bool,
|
||||
|
||||
/// Shortcut for `--name One --validator` with session keys for `One` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])]
|
||||
pub one: bool,
|
||||
|
||||
/// Shortcut for `--name Two --validator` with session keys for `Two` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])]
|
||||
pub two: bool,
|
||||
|
||||
/// Enable authoring even when offline.
|
||||
#[structopt(long = "force-authoring")]
|
||||
#[clap(long)]
|
||||
pub force_authoring: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub keystore_params: KeystoreParams,
|
||||
|
||||
/// The size of the instances cache for each runtime.
|
||||
///
|
||||
/// The default value is 8 and the values higher than 256 are ignored.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub max_runtime_instances: Option<usize>,
|
||||
|
||||
/// Maximum number of different runtimes that can be cached.
|
||||
#[structopt(long, default_value = "2")]
|
||||
#[clap(long, default_value = "2")]
|
||||
pub runtime_cache_size: u8,
|
||||
|
||||
/// Run a temporary node.
|
||||
@@ -251,7 +251,7 @@ pub struct RunCmd {
|
||||
/// which includes: database, node key and keystore.
|
||||
///
|
||||
/// When `--dev` is given and no explicit `--base-path`, this option is implied.
|
||||
#[structopt(long, conflicts_with = "base-path")]
|
||||
#[clap(long, conflicts_with = "base-path")]
|
||||
pub tmp: bool,
|
||||
}
|
||||
|
||||
@@ -562,8 +562,7 @@ fn parse_telemetry_endpoints(s: &str) -> std::result::Result<(String, u8), Telem
|
||||
|
||||
/// CORS setting
|
||||
///
|
||||
/// The type is introduced to overcome `Option<Option<T>>`
|
||||
/// handling of `structopt`.
|
||||
/// The type is introduced to overcome `Option<Option<T>>` handling of `clap`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Cors {
|
||||
/// All hosts allowed.
|
||||
@@ -582,7 +581,7 @@ impl From<Cors> for Option<Vec<String>> {
|
||||
}
|
||||
|
||||
/// Parse cors origins.
|
||||
fn parse_cors(s: &str) -> std::result::Result<Cors, Box<dyn std::error::Error>> {
|
||||
fn parse_cors(s: &str) -> Cors {
|
||||
let mut is_all = false;
|
||||
let mut origins = Vec::new();
|
||||
for part in s.split(',') {
|
||||
@@ -595,7 +594,11 @@ fn parse_cors(s: &str) -> std::result::Result<Cors, Box<dyn std::error::Error>>
|
||||
}
|
||||
}
|
||||
|
||||
Ok(if is_all { Cors::All } else { Cors::List(origins) })
|
||||
if is_all {
|
||||
Cors::All
|
||||
} else {
|
||||
Cors::List(origins)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user