mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
sc-cli: Fix bugs after switching to clap3 (#10920)
* sc-cli: Fix bugs after switching to clap3 Before switching to clap3 we support cli options like `--reserved-nodes A B` and after you needed to pass `--reserved-nodes` cli option multiple times `--reserved-nodes A --reserved-nodes B`. This is fixed by setting `multiple_occurrences(true)` option. This also done for all the other `Vec` cli options in `sc-cli`. Besides that `--sync` wasn't supporting case insensitive parsing of the value. This is now also supported. For both regressions a test is added. Besides that the pr removes all the `rename_all = PascalCase` attributes, because they are not needed. All other `ArgEnum`s were checked and all are already using `ignore_case(true)`. * Bring back `PascalCase`, because otherwise it falls back to `kebab-case`...
This commit is contained in:
@@ -34,11 +34,11 @@ use std::{borrow::Cow, path::PathBuf};
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct NetworkParams {
|
||||
/// Specify a list of bootnodes.
|
||||
#[clap(long, value_name = "ADDR")]
|
||||
#[clap(long, value_name = "ADDR", multiple_values(true))]
|
||||
pub bootnodes: Vec<MultiaddrWithPeerId>,
|
||||
|
||||
/// Specify a list of reserved node addresses.
|
||||
#[clap(long, value_name = "ADDR")]
|
||||
#[clap(long, value_name = "ADDR", multiple_values(true))]
|
||||
pub reserved_nodes: Vec<MultiaddrWithPeerId>,
|
||||
|
||||
/// Whether to only synchronize the chain with reserved nodes.
|
||||
@@ -54,7 +54,7 @@ pub struct NetworkParams {
|
||||
|
||||
/// The public address that other nodes will use to connect to it.
|
||||
/// This can be used if there's a proxy in front of this node.
|
||||
#[clap(long, value_name = "PUBLIC_ADDR")]
|
||||
#[clap(long, value_name = "PUBLIC_ADDR", multiple_values(true))]
|
||||
pub public_addr: Vec<Multiaddr>,
|
||||
|
||||
/// Listen on this multiaddress.
|
||||
@@ -62,7 +62,7 @@ pub struct NetworkParams {
|
||||
/// By default:
|
||||
/// If `--validator` is passed: `/ip4/0.0.0.0/tcp/<port>` and `/ip6/[::]/tcp/<port>`.
|
||||
/// Otherwise: `/ip4/0.0.0.0/tcp/<port>/ws` and `/ip6/[::]/tcp/<port>/ws`.
|
||||
#[clap(long, value_name = "LISTEN_ADDR")]
|
||||
#[clap(long, value_name = "LISTEN_ADDR", multiple_values(true))]
|
||||
pub listen_addr: Vec<Multiaddr>,
|
||||
|
||||
/// Specify p2p protocol TCP port.
|
||||
@@ -137,7 +137,7 @@ pub struct NetworkParams {
|
||||
/// - `Fast`: Download blocks and the latest state only.
|
||||
///
|
||||
/// - `FastUnsafe`: Same as `Fast`, but skip downloading state proofs.
|
||||
#[clap(long, arg_enum, value_name = "SYNC_MODE", default_value = "Full")]
|
||||
#[clap(long, arg_enum, value_name = "SYNC_MODE", default_value = "Full", ignore_case(true))]
|
||||
pub sync: SyncMode,
|
||||
}
|
||||
|
||||
@@ -237,3 +237,55 @@ impl NetworkParams {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
#[clap(flatten)]
|
||||
network_params: NetworkParams,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reserved_nodes_multiple_values_and_occurrences() {
|
||||
let params = Cli::try_parse_from([
|
||||
"",
|
||||
"--reserved-nodes",
|
||||
"/ip4/0.0.0.0/tcp/501/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS",
|
||||
"/ip4/0.0.0.0/tcp/502/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS",
|
||||
"--reserved-nodes",
|
||||
"/ip4/0.0.0.0/tcp/503/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS",
|
||||
])
|
||||
.expect("Parses network params");
|
||||
|
||||
let expected = vec![
|
||||
MultiaddrWithPeerId::try_from(
|
||||
"/ip4/0.0.0.0/tcp/501/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS"
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap(),
|
||||
MultiaddrWithPeerId::try_from(
|
||||
"/ip4/0.0.0.0/tcp/502/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS"
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap(),
|
||||
MultiaddrWithPeerId::try_from(
|
||||
"/ip4/0.0.0.0/tcp/503/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS"
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap(),
|
||||
];
|
||||
|
||||
assert_eq!(expected, params.network_params.reserved_nodes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_ingores_case() {
|
||||
let params = Cli::try_parse_from(["", "--sync", "wArP"]).expect("Parses network params");
|
||||
|
||||
assert_eq!(SyncMode::Warp, params.network_params.sync);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct SharedParams {
|
||||
///
|
||||
/// Log levels (least to most verbose) are error, warn, info, debug, and trace.
|
||||
/// By default, all targets log `info`. The global log level can be set with -l<level>.
|
||||
#[clap(short = 'l', long, value_name = "LOG_PATTERN")]
|
||||
#[clap(short = 'l', long, value_name = "LOG_PATTERN", multiple_values(true))]
|
||||
pub log: Vec<String>,
|
||||
|
||||
/// Enable detailed log output.
|
||||
|
||||
Reference in New Issue
Block a user