mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-07 03:48:01 +00:00
Bump clap to 4.0.x and adjust to best practices (#12381)
* Bump clap to 3.2.22 * Replace `from_os_str` with `value_parser` * Replace `from_str` and `try_from_str` with `value_parser` * Move possible_values to the new format * Remove unwanted print * Add missing match branch * Update clap to 4.0.9 and make it compile * Replace deprecated `clap` macro with `command` and `value` * Move remaining `clap` attributes to `arg` * Remove no-op value_parsers * Adjust value_parser for state_version * Remove "deprecated" feature flag and bump to 4.0.11 * Improve range Co-authored-by: Bastian Köcher <git@kchr.de> * Apply suggestions * Trigger CI * Fix unused error warning * Fix doc errors * Fix ArgGroup naming conflict * Change default_value to default_value_t * Use 1.. instead of 0.. Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -27,7 +27,7 @@ mod transaction_pool_params;
|
||||
|
||||
use crate::arg_enums::{CryptoScheme, OutputType};
|
||||
use clap::Args;
|
||||
use sp_core::crypto::Ss58AddressFormat;
|
||||
use sp_core::crypto::{Ss58AddressFormat, Ss58AddressFormatRegistry};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
@@ -40,6 +40,17 @@ pub use crate::params::{
|
||||
transaction_pool_params::*,
|
||||
};
|
||||
|
||||
/// Parse Ss58AddressFormat
|
||||
pub fn parse_ss58_address_format(x: &str) -> Result<Ss58AddressFormat, String> {
|
||||
match Ss58AddressFormatRegistry::try_from(x) {
|
||||
Ok(format_registry) => Ok(format_registry.into()),
|
||||
Err(_) => Err(format!(
|
||||
"Unable to parse variant. Known variants: {:?}",
|
||||
Ss58AddressFormat::all_names()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type of `String` that holds an unsigned integer of arbitrary size, formatted as a
|
||||
/// decimal.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -118,7 +129,7 @@ impl BlockNumberOrHash {
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct CryptoSchemeFlag {
|
||||
/// cryptography scheme
|
||||
#[clap(long, value_name = "SCHEME", arg_enum, ignore_case = true, default_value = "sr25519")]
|
||||
#[arg(long, value_name = "SCHEME", value_enum, ignore_case = true, default_value_t = CryptoScheme::Sr25519)]
|
||||
pub scheme: CryptoScheme,
|
||||
}
|
||||
|
||||
@@ -126,7 +137,7 @@ pub struct CryptoSchemeFlag {
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct OutputTypeFlag {
|
||||
/// output format
|
||||
#[clap(long, value_name = "FORMAT", arg_enum, ignore_case = true, default_value = "text")]
|
||||
#[arg(long, value_name = "FORMAT", value_enum, ignore_case = true, default_value_t = OutputType::Text)]
|
||||
pub output_type: OutputType,
|
||||
}
|
||||
|
||||
@@ -134,13 +145,12 @@ pub struct OutputTypeFlag {
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct NetworkSchemeFlag {
|
||||
/// network address format
|
||||
#[clap(
|
||||
#[arg(
|
||||
short = 'n',
|
||||
long,
|
||||
value_name = "NETWORK",
|
||||
possible_values = &Ss58AddressFormat::all_names()[..],
|
||||
ignore_case = true,
|
||||
parse(try_from_str = Ss58AddressFormat::try_from),
|
||||
value_parser = parse_ss58_address_format,
|
||||
)]
|
||||
pub network: Option<Ss58AddressFormat>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user