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
@@ -21,6 +21,7 @@ use crate::{
params::{NodeKeyParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use log::info;
use sc_network::config::build_multiaddr;
use sc_service::{
@@ -28,28 +29,27 @@ use sc_service::{
ChainSpec,
};
use std::io::Write;
use structopt::StructOpt;
/// The `build-spec` command used to build a specification.
#[derive(Debug, StructOpt, Clone)]
#[derive(Debug, Clone, Parser)]
pub struct BuildSpecCmd {
/// Force raw genesis storage output.
#[structopt(long = "raw")]
#[clap(long)]
pub raw: bool,
/// Disable adding the default bootnode to the specification.
///
/// By default the `/ip4/127.0.0.1/tcp/30333/p2p/NODE_PEER_ID` bootnode is added to the
/// specification when no bootnode exists.
#[structopt(long = "disable-default-bootnode")]
#[clap(long)]
pub disable_default_bootnode: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub node_key_params: NodeKeyParams,
}
@@ -21,30 +21,30 @@ use crate::{
params::{BlockNumberOrHash, ImportParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use sc_client_api::{BlockBackend, HeaderBackend};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, str::FromStr, sync::Arc};
use structopt::StructOpt;
/// The `check-block` command used to validate blocks.
#[derive(Debug, StructOpt, Clone)]
#[derive(Debug, Clone, Parser)]
pub struct CheckBlockCmd {
/// Block hash or number
#[structopt(value_name = "HASH or NUMBER")]
#[clap(value_name = "HASH or NUMBER")]
pub input: BlockNumberOrHash,
/// The default number of 64KB pages to ever allocate for Wasm execution.
///
/// Don't alter this unless you know what you're doing.
#[structopt(long = "default-heap-pages", value_name = "COUNT")]
#[clap(long, value_name = "COUNT")]
pub default_heap_pages: Option<u32>,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub import_params: ImportParams,
}
@@ -21,46 +21,46 @@ use crate::{
params::{DatabaseParams, GenericNumber, PruningParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use log::info;
use sc_client_api::{BlockBackend, UsageProvider};
use sc_service::{chain_ops::export_blocks, config::DatabaseSource};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, fs, io, path::PathBuf, str::FromStr, sync::Arc};
use structopt::StructOpt;
/// The `export-blocks` command used to export blocks.
#[derive(Debug, StructOpt, Clone)]
#[derive(Debug, Clone, Parser)]
pub struct ExportBlocksCmd {
/// Output file name or stdout if unspecified.
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
pub output: Option<PathBuf>,
/// Specify starting block number.
///
/// Default is 1.
#[structopt(long = "from", value_name = "BLOCK")]
#[clap(long, value_name = "BLOCK")]
pub from: Option<GenericNumber>,
/// Specify last block number.
///
/// Default is best block.
#[structopt(long = "to", value_name = "BLOCK")]
#[clap(long, value_name = "BLOCK")]
pub to: Option<GenericNumber>,
/// Use binary output rather than JSON.
#[structopt(long)]
#[clap(long)]
pub binary: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub pruning_params: PruningParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub database_params: DatabaseParams,
}
@@ -21,26 +21,26 @@ use crate::{
params::{BlockNumberOrHash, PruningParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use log::info;
use sc_client_api::{StorageProvider, UsageProvider};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, io::Write, str::FromStr, sync::Arc};
use structopt::StructOpt;
/// The `export-state` command used to export the state of a given block into
/// a chain spec.
#[derive(Debug, StructOpt, Clone)]
#[derive(Debug, Clone, Parser)]
pub struct ExportStateCmd {
/// Block hash or number.
#[structopt(value_name = "HASH or NUMBER")]
#[clap(value_name = "HASH or NUMBER")]
pub input: Option<BlockNumberOrHash>,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub pruning_params: PruningParams,
}
+10 -11
View File
@@ -21,30 +21,30 @@ use crate::{
NetworkSchemeFlag, OutputTypeFlag,
};
use bip39::{Language, Mnemonic, MnemonicType};
use structopt::StructOpt;
use clap::Parser;
/// The `generate` command
#[derive(Debug, StructOpt, Clone)]
#[structopt(name = "generate", about = "Generate a random account")]
#[derive(Debug, Clone, Parser)]
#[clap(name = "generate", about = "Generate a random account")]
pub struct GenerateCmd {
/// The number of words in the phrase to generate. One of 12 (default), 15, 18, 21 and 24.
#[structopt(long, short = "w", value_name = "WORDS")]
#[clap(short = 'w', long, value_name = "WORDS")]
words: Option<usize>,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub keystore_params: KeystoreParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub network_scheme: NetworkSchemeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub output_scheme: OutputTypeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub crypto_scheme: CryptoSchemeFlag,
}
@@ -78,12 +78,11 @@ impl GenerateCmd {
#[cfg(test)]
mod tests {
use super::GenerateCmd;
use structopt::StructOpt;
use super::*;
#[test]
fn generate() {
let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]);
let generate = GenerateCmd::parse_from(&["generate", "--password", "12345"]);
assert!(generate.run().is_ok())
}
}
@@ -18,13 +18,13 @@
//! Implementation of the `generate-node-key` subcommand
use crate::Error;
use clap::Parser;
use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey};
use std::{fs, path::PathBuf};
use structopt::StructOpt;
/// The `generate-node-key` command
#[derive(Debug, StructOpt)]
#[structopt(
#[derive(Debug, Parser)]
#[clap(
name = "generate-node-key",
about = "Generate a random node libp2p key, save it to \
file or print it to stdout and print its peer ID to stderr"
@@ -33,7 +33,7 @@ pub struct GenerateNodeKeyCmd {
/// Name of file to save secret key to.
///
/// If not given, the secret key is printed to stdout.
#[structopt(long)]
#[clap(long)]
file: Option<PathBuf>,
}
@@ -66,7 +66,7 @@ mod tests {
fn generate_node_key() {
let mut file = Builder::new().prefix("keyfile").tempfile().unwrap();
let file_path = file.path().display().to_string();
let generate = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", &file_path]);
let generate = GenerateNodeKeyCmd::parse_from(&["generate-node-key", "--file", &file_path]);
assert!(generate.run().is_ok());
let mut buf = String::new();
assert!(file.read_to_string(&mut buf).is_ok());
@@ -21,6 +21,7 @@ use crate::{
params::{ImportParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use sc_client_api::HeaderBackend;
use sc_service::chain_ops::import_blocks;
use sp_runtime::traits::Block as BlockT;
@@ -31,31 +32,30 @@ use std::{
path::PathBuf,
sync::Arc,
};
use structopt::StructOpt;
/// The `import-blocks` command used to import blocks.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct ImportBlocksCmd {
/// Input file or stdin if unspecified.
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
pub input: Option<PathBuf>,
/// The default number of 64KB pages to ever allocate for Wasm execution.
///
/// Don't alter this unless you know what you're doing.
#[structopt(long = "default-heap-pages", value_name = "COUNT")]
#[clap(long, value_name = "COUNT")]
pub default_heap_pages: Option<u32>,
/// Try importing blocks from binary format rather than JSON.
#[structopt(long)]
#[clap(long)]
pub binary: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub import_params: ImportParams,
}
@@ -20,42 +20,37 @@
use crate::{
utils, with_crypto_scheme, CryptoScheme, Error, KeystoreParams, SharedParams, SubstrateCli,
};
use clap::Parser;
use sc_keystore::LocalKeystore;
use sc_service::config::{BasePath, KeystoreConfig};
use sp_core::crypto::{KeyTypeId, SecretString};
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use std::{convert::TryFrom, sync::Arc};
use structopt::StructOpt;
/// The `insert` command
#[derive(Debug, StructOpt, Clone)]
#[structopt(name = "insert", about = "Insert a key to the keystore of a node.")]
#[derive(Debug, Clone, Parser)]
#[clap(name = "insert", about = "Insert a key to the keystore of a node.")]
pub struct InsertKeyCmd {
/// The secret key URI.
/// If the value is a file, the file content is used as URI.
/// If not given, you will be prompted for the URI.
#[structopt(long)]
#[clap(long)]
suri: Option<String>,
/// Key type, examples: "gran", or "imon"
#[structopt(long)]
#[clap(long)]
key_type: String,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub keystore_params: KeystoreParams,
/// The cryptography scheme that should be used to generate the key out of the given URI.
#[structopt(
long,
value_name = "SCHEME",
possible_values = &CryptoScheme::variants(),
case_insensitive = true,
)]
#[clap(long, value_name = "SCHEME", arg_enum, ignore_case = true)]
pub scheme: CryptoScheme,
}
@@ -100,7 +95,6 @@ mod tests {
use super::*;
use sc_service::{ChainSpec, ChainType, GenericChainSpec, NoExtension};
use sp_core::{sr25519::Pair, ByteArray, Pair as _};
use structopt::StructOpt;
use tempfile::TempDir;
struct Cli;
@@ -156,7 +150,7 @@ mod tests {
let path_str = format!("{}", path.path().display());
let (key, uri, _) = Pair::generate_with_phrase(None);
let inspect = InsertKeyCmd::from_iter(&[
let inspect = InsertKeyCmd::parse_from(&[
"insert-key",
"-d",
&path_str,
@@ -21,13 +21,13 @@ use crate::{
utils::{self, print_from_public, print_from_uri},
with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, NetworkSchemeFlag, OutputTypeFlag,
};
use clap::Parser;
use sp_core::crypto::{ExposeSecret, SecretString, SecretUri, Ss58Codec};
use std::str::FromStr;
use structopt::StructOpt;
/// The `inspect` command
#[derive(Debug, StructOpt)]
#[structopt(
#[derive(Debug, Parser)]
#[clap(
name = "inspect",
about = "Gets a public key and a SS58 address from the provided Secret URI"
)]
@@ -44,23 +44,23 @@ pub struct InspectKeyCmd {
uri: Option<String>,
/// Is the given `uri` a hex encoded public key?
#[structopt(long)]
#[clap(long)]
public: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub keystore_params: KeystoreParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub network_scheme: NetworkSchemeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub output_scheme: OutputTypeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub crypto_scheme: CryptoSchemeFlag,
/// Expect that `--uri` has the given public key/account-id.
@@ -72,7 +72,7 @@ pub struct InspectKeyCmd {
///
/// If there is no derivation in `--uri`, the public key will be checked against the public key
/// of `--uri` directly.
#[structopt(long, conflicts_with = "public")]
#[clap(long, conflicts_with = "public")]
pub expect_public: Option<String>,
}
@@ -158,7 +158,6 @@ mod tests {
use super::*;
use sp_core::crypto::{ByteArray, Pair};
use sp_runtime::traits::IdentifyAccount;
use structopt::StructOpt;
#[test]
fn inspect() {
@@ -166,10 +165,10 @@ mod tests {
"remember fiber forum demise paper uniform squirrel feel access exclude casual effort";
let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5";
let inspect = InspectKeyCmd::from_iter(&["inspect-key", words, "--password", "12345"]);
let inspect = InspectKeyCmd::parse_from(&["inspect-key", words, "--password", "12345"]);
assert!(inspect.run().is_ok());
let inspect = InspectKeyCmd::from_iter(&["inspect-key", seed]);
let inspect = InspectKeyCmd::parse_from(&["inspect-key", seed]);
assert!(inspect.run().is_ok());
}
@@ -177,14 +176,14 @@ mod tests {
fn inspect_public_key() {
let public = "0x12e76e0ae8ce41b6516cce52b3f23a08dcb4cfeed53c6ee8f5eb9f7367341069";
let inspect = InspectKeyCmd::from_iter(&["inspect-key", "--public", public]);
let inspect = InspectKeyCmd::parse_from(&["inspect-key", "--public", public]);
assert!(inspect.run().is_ok());
}
#[test]
fn inspect_with_expected_public_key() {
let check_cmd = |seed, expected_public, success| {
let inspect = InspectKeyCmd::from_iter(&[
let inspect = InspectKeyCmd::parse_from(&[
"inspect-key",
"--expect-public",
expected_public,
@@ -18,23 +18,23 @@
//! Implementation of the `inspect-node-key` subcommand
use crate::{Error, NetworkSchemeFlag};
use clap::Parser;
use libp2p::identity::{ed25519, PublicKey};
use std::{fs, path::PathBuf};
use structopt::StructOpt;
/// The `inspect-node-key` command
#[derive(Debug, StructOpt)]
#[structopt(
#[derive(Debug, Parser)]
#[clap(
name = "inspect-node-key",
about = "Print the peer ID corresponding to the node key in the given file."
)]
pub struct InspectNodeKeyCmd {
/// Name of file to read the secret key from.
#[structopt(long)]
#[clap(long)]
file: PathBuf,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub network_scheme: NetworkSchemeFlag,
}
@@ -63,11 +63,11 @@ mod tests {
fn inspect_node_key() {
let path = tempfile::tempdir().unwrap().into_path().join("node-id").into_os_string();
let path = path.to_str().unwrap();
let cmd = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", path.clone()]);
let cmd = GenerateNodeKeyCmd::parse_from(&["generate-node-key", "--file", path.clone()]);
assert!(cmd.run().is_ok());
let cmd = InspectNodeKeyCmd::from_iter(&["inspect-node-key", "--file", path]);
let cmd = InspectNodeKeyCmd::parse_from(&["inspect-node-key", "--file", path]);
assert!(cmd.run().is_ok());
}
}
+2 -4
View File
@@ -17,16 +17,14 @@
//! Key related CLI utilities
use crate::{Error, SubstrateCli};
use structopt::StructOpt;
use super::{
generate::GenerateCmd, generate_node_key::GenerateNodeKeyCmd, insert_key::InsertKeyCmd,
inspect_key::InspectKeyCmd, inspect_node_key::InspectNodeKeyCmd,
};
use crate::{Error, SubstrateCli};
/// Key utilities for the cli.
#[derive(Debug, StructOpt)]
#[derive(Debug, clap::Subcommand)]
pub enum KeySubcommand {
/// Generate a random node libp2p key, save it to file or print it to stdout
/// and print its peer ID to stderr.
@@ -21,27 +21,27 @@ use crate::{
params::{DatabaseParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use sc_service::DatabaseSource;
use std::{
fmt::Debug,
fs,
io::{self, Write},
};
use structopt::StructOpt;
/// The `purge-chain` command used to remove the whole chain.
#[derive(Debug, StructOpt, Clone)]
#[derive(Debug, Clone, Parser)]
pub struct PurgeChainCmd {
/// Skip interactive prompt by answering yes automatically.
#[structopt(short = "y")]
#[clap(short = 'y')]
pub yes: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub database_params: DatabaseParams,
}
@@ -21,25 +21,25 @@ use crate::{
params::{GenericNumber, PruningParams, SharedParams},
CliConfiguration,
};
use clap::Parser;
use sc_client_api::{Backend, UsageProvider};
use sc_service::chain_ops::revert_chain;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, str::FromStr, sync::Arc};
use structopt::StructOpt;
/// The `revert` command used revert the chain to a previous state.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct RevertCmd {
/// Number of blocks to revert.
#[structopt(default_value = "256")]
#[clap(default_value = "256")]
pub num: GenericNumber,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub pruning_params: PruningParams,
}
+50 -47
View File
@@ -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)]
+10 -11
View File
@@ -18,34 +18,34 @@
//! Implementation of the `sign` subcommand
use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag, KeystoreParams};
use clap::Parser;
use sp_core::crypto::SecretString;
use structopt::StructOpt;
/// The `sign` command
#[derive(Debug, StructOpt, Clone)]
#[structopt(name = "sign", about = "Sign a message, with a given (secret) key")]
#[derive(Debug, Clone, Parser)]
#[clap(name = "sign", about = "Sign a message, with a given (secret) key")]
pub struct SignCmd {
/// The secret key URI.
/// If the value is a file, the file content is used as URI.
/// If not given, you will be prompted for the URI.
#[structopt(long)]
#[clap(long)]
suri: Option<String>,
/// Message to sign, if not provided you will be prompted to
/// pass the message via STDIN
#[structopt(long)]
#[clap(long)]
message: Option<String>,
/// The message on STDIN is hex-encoded data
#[structopt(long)]
#[clap(long)]
hex: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub keystore_params: KeystoreParams,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub crypto_scheme: CryptoSchemeFlag,
}
@@ -75,14 +75,13 @@ fn sign<P: sp_core::Pair>(
#[cfg(test)]
mod test {
use super::SignCmd;
use structopt::StructOpt;
use super::*;
#[test]
fn sign() {
let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5";
let sign = SignCmd::from_iter(&[
let sign = SignCmd::parse_from(&[
"sign",
"--suri",
seed,
+8 -9
View File
@@ -21,30 +21,30 @@
use crate::{
error, utils, with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag,
};
use clap::Parser;
use rand::{rngs::OsRng, RngCore};
use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec};
use sp_runtime::traits::IdentifyAccount;
use structopt::StructOpt;
use utils::print_from_uri;
/// The `vanity` command
#[derive(Debug, StructOpt, Clone)]
#[structopt(name = "vanity", about = "Generate a seed that provides a vanity address")]
#[derive(Debug, Clone, Parser)]
#[clap(name = "vanity", about = "Generate a seed that provides a vanity address")]
pub struct VanityCmd {
/// Desired pattern
#[structopt(long, parse(try_from_str = assert_non_empty_string))]
#[clap(long, parse(try_from_str = assert_non_empty_string))]
pattern: String,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
network_scheme: NetworkSchemeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
output_scheme: OutputTypeFlag,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
crypto_scheme: CryptoSchemeFlag,
}
@@ -166,13 +166,12 @@ mod tests {
crypto::{default_ss58_version, Ss58AddressFormatRegistry, Ss58Codec},
sr25519, Pair,
};
use structopt::StructOpt;
#[cfg(feature = "bench")]
use test::Bencher;
#[test]
fn vanity() {
let vanity = VanityCmd::from_iter(&["vanity", "--pattern", "j"]);
let vanity = VanityCmd::parse_from(&["vanity", "--pattern", "j"]);
assert!(vanity.run().is_ok());
}
+6 -6
View File
@@ -19,12 +19,12 @@
//! implementation of the `verify` subcommand
use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag};
use clap::Parser;
use sp_core::crypto::{ByteArray, Ss58Codec};
use structopt::StructOpt;
/// The `verify` command
#[derive(Debug, StructOpt, Clone)]
#[structopt(
#[derive(Debug, Clone, Parser)]
#[clap(
name = "verify",
about = "Verify a signature for a message, provided on STDIN, with a given (public or secret) key"
)]
@@ -39,15 +39,15 @@ pub struct VerifyCmd {
/// Message to verify, if not provided you will be prompted to
/// pass the message via STDIN
#[structopt(long)]
#[clap(long)]
message: Option<String>,
/// The message on STDIN is hex-encoded data
#[structopt(long)]
#[clap(long)]
hex: bool,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub crypto_scheme: CryptoSchemeFlag,
}