update clap to v3: clap-utils (error)
This commit is contained in:
@@ -10,7 +10,7 @@ documentation = "https://docs.rs/solana-clap-utils"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "3.1.5"
|
clap = { version = "3.1.5", features = ["cargo"] }
|
||||||
rpassword = "5.0"
|
rpassword = "5.0"
|
||||||
solana-perf = { path = "../perf", version = "=1.10.1" }
|
solana-perf = { path = "../perf", version = "=1.10.1" }
|
||||||
solana-remote-wallet = { path = "../remote-wallet", version = "=1.10.1", default-features = false}
|
solana-remote-wallet = { path = "../remote-wallet", version = "=1.10.1", default-features = false}
|
||||||
|
@@ -11,11 +11,11 @@ pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant {
|
|||||||
is also passed. Defaults to the client keypair.",
|
is also passed. Defaults to the client keypair.",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn fee_payer_arg<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn fee_payer_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(FEE_PAYER_ARG.name)
|
Arg::new(FEE_PAYER_ARG.name)
|
||||||
.long(FEE_PAYER_ARG.long)
|
.long(FEE_PAYER_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("KEYPAIR")
|
.value_name("KEYPAIR")
|
||||||
.validator(input_validators::is_valid_signer)
|
.validator(|s| input_validators::is_valid_signer(s))
|
||||||
.help(FEE_PAYER_ARG.help)
|
.help(FEE_PAYER_ARG.help)
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ use {
|
|||||||
pub const STDOUT_OUTFILE_TOKEN: &str = "-";
|
pub const STDOUT_OUTFILE_TOKEN: &str = "-";
|
||||||
|
|
||||||
// Return parsed values from matches at `name`
|
// Return parsed values from matches at `name`
|
||||||
pub fn values_of<T>(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<T>>
|
pub fn values_of<T>(matches: &ArgMatches, name: &str) -> Option<Vec<T>>
|
||||||
where
|
where
|
||||||
T: std::str::FromStr,
|
T: std::str::FromStr,
|
||||||
<T as std::str::FromStr>::Err: std::fmt::Debug,
|
<T as std::str::FromStr>::Err: std::fmt::Debug,
|
||||||
@@ -32,7 +32,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return a parsed value from matches at `name`
|
// Return a parsed value from matches at `name`
|
||||||
pub fn value_of<T>(matches: &ArgMatches<'_>, name: &str) -> Option<T>
|
pub fn value_of<T>(matches: &ArgMatches, name: &str) -> Option<T>
|
||||||
where
|
where
|
||||||
T: std::str::FromStr,
|
T: std::str::FromStr,
|
||||||
<T as std::str::FromStr>::Err: std::fmt::Debug,
|
<T as std::str::FromStr>::Err: std::fmt::Debug,
|
||||||
@@ -45,7 +45,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn unix_timestamp_from_rfc3339_datetime(
|
pub fn unix_timestamp_from_rfc3339_datetime(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Option<UnixTimestamp> {
|
) -> Option<UnixTimestamp> {
|
||||||
matches.value_of(name).and_then(|value| {
|
matches.value_of(name).and_then(|value| {
|
||||||
@@ -56,7 +56,7 @@ pub fn unix_timestamp_from_rfc3339_datetime(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the keypair for an argument with filename `name` or None if not present.
|
// Return the keypair for an argument with filename `name` or None if not present.
|
||||||
pub fn keypair_of(matches: &ArgMatches<'_>, name: &str) -> Option<Keypair> {
|
pub fn keypair_of(matches: &ArgMatches, name: &str) -> Option<Keypair> {
|
||||||
if let Some(value) = matches.value_of(name) {
|
if let Some(value) = matches.value_of(name) {
|
||||||
if value == ASK_KEYWORD {
|
if value == ASK_KEYWORD {
|
||||||
let skip_validation = matches.is_present(SKIP_SEED_PHRASE_VALIDATION_ARG.name);
|
let skip_validation = matches.is_present(SKIP_SEED_PHRASE_VALIDATION_ARG.name);
|
||||||
@@ -69,7 +69,7 @@ pub fn keypair_of(matches: &ArgMatches<'_>, name: &str) -> Option<Keypair> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keypairs_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<Keypair>> {
|
pub fn keypairs_of(matches: &ArgMatches, name: &str) -> Option<Vec<Keypair>> {
|
||||||
matches.values_of(name).map(|values| {
|
matches.values_of(name).map(|values| {
|
||||||
values
|
values
|
||||||
.filter_map(|value| {
|
.filter_map(|value| {
|
||||||
@@ -86,11 +86,11 @@ pub fn keypairs_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<Keypair>>
|
|||||||
|
|
||||||
// Return a pubkey for an argument that can itself be parsed into a pubkey,
|
// Return a pubkey for an argument that can itself be parsed into a pubkey,
|
||||||
// or is a filename that can be read as a keypair
|
// or is a filename that can be read as a keypair
|
||||||
pub fn pubkey_of(matches: &ArgMatches<'_>, name: &str) -> Option<Pubkey> {
|
pub fn pubkey_of(matches: &ArgMatches, name: &str) -> Option<Pubkey> {
|
||||||
value_of(matches, name).or_else(|| keypair_of(matches, name).map(|keypair| keypair.pubkey()))
|
value_of(matches, name).or_else(|| keypair_of(matches, name).map(|keypair| keypair.pubkey()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pubkeys_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<Pubkey>> {
|
pub fn pubkeys_of(matches: &ArgMatches, name: &str) -> Option<Vec<Pubkey>> {
|
||||||
matches.values_of(name).map(|values| {
|
matches.values_of(name).map(|values| {
|
||||||
values
|
values
|
||||||
.map(|value| {
|
.map(|value| {
|
||||||
@@ -105,7 +105,7 @@ pub fn pubkeys_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<Pubkey>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return pubkey/signature pairs for a string of the form pubkey=signature
|
// Return pubkey/signature pairs for a string of the form pubkey=signature
|
||||||
pub fn pubkeys_sigs_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<(Pubkey, Signature)>> {
|
pub fn pubkeys_sigs_of(matches: &ArgMatches, name: &str) -> Option<Vec<(Pubkey, Signature)>> {
|
||||||
matches.values_of(name).map(|values| {
|
matches.values_of(name).map(|values| {
|
||||||
values
|
values
|
||||||
.map(|pubkey_signer_string| {
|
.map(|pubkey_signer_string| {
|
||||||
@@ -121,7 +121,7 @@ pub fn pubkeys_sigs_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<(Pubk
|
|||||||
// Return a signer from matches at `name`
|
// Return a signer from matches at `name`
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn signer_of(
|
pub fn signer_of(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches,
|
||||||
name: &str,
|
name: &str,
|
||||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||||
) -> Result<(Option<Box<dyn Signer>>, Option<Pubkey>), Box<dyn std::error::Error>> {
|
) -> Result<(Option<Box<dyn Signer>>, Option<Pubkey>), Box<dyn std::error::Error>> {
|
||||||
@@ -135,7 +135,7 @@ pub fn signer_of(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pubkey_of_signer(
|
pub fn pubkey_of_signer(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches,
|
||||||
name: &str,
|
name: &str,
|
||||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||||
) -> Result<Option<Pubkey>, Box<dyn std::error::Error>> {
|
) -> Result<Option<Pubkey>, Box<dyn std::error::Error>> {
|
||||||
@@ -152,7 +152,7 @@ pub fn pubkey_of_signer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pubkeys_of_multiple_signers(
|
pub fn pubkeys_of_multiple_signers(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches,
|
||||||
name: &str,
|
name: &str,
|
||||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||||
) -> Result<Option<Vec<Pubkey>>, Box<dyn std::error::Error>> {
|
) -> Result<Option<Vec<Pubkey>>, Box<dyn std::error::Error>> {
|
||||||
@@ -168,7 +168,7 @@ pub fn pubkeys_of_multiple_signers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_signer(
|
pub fn resolve_signer(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches,
|
||||||
name: &str,
|
name: &str,
|
||||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||||
) -> Result<Option<String>, Box<dyn std::error::Error>> {
|
) -> Result<Option<String>, Box<dyn std::error::Error>> {
|
||||||
@@ -180,15 +180,15 @@ pub fn resolve_signer(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lamports_of_sol(matches: &ArgMatches<'_>, name: &str) -> Option<u64> {
|
pub fn lamports_of_sol(matches: &ArgMatches, name: &str) -> Option<u64> {
|
||||||
value_of(matches, name).map(sol_to_lamports)
|
value_of(matches, name).map(sol_to_lamports)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cluster_type_of(matches: &ArgMatches<'_>, name: &str) -> Option<ClusterType> {
|
pub fn cluster_type_of(matches: &ArgMatches, name: &str) -> Option<ClusterType> {
|
||||||
value_of(matches, name)
|
value_of(matches, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn commitment_of(matches: &ArgMatches<'_>, name: &str) -> Option<CommitmentConfig> {
|
pub fn commitment_of(matches: &ArgMatches, name: &str) -> Option<CommitmentConfig> {
|
||||||
matches
|
matches
|
||||||
.value_of(name)
|
.value_of(name)
|
||||||
.map(|value| CommitmentConfig::from_str(value).unwrap_or_default())
|
.map(|value| CommitmentConfig::from_str(value).unwrap_or_default())
|
||||||
|
@@ -241,7 +241,7 @@ impl DefaultSigner {
|
|||||||
pub fn generate_unique_signers(
|
pub fn generate_unique_signers(
|
||||||
&self,
|
&self,
|
||||||
bulk_signers: Vec<Option<Box<dyn Signer>>>,
|
bulk_signers: Vec<Option<Box<dyn Signer>>>,
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches,
|
||||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||||
) -> Result<CliSignerInfo, Box<dyn error::Error>> {
|
) -> Result<CliSignerInfo, Box<dyn error::Error>> {
|
||||||
let mut unique_signers = vec![];
|
let mut unique_signers = vec![];
|
||||||
|
@@ -6,8 +6,8 @@ pub const MEMO_ARG: ArgConstant<'static> = ArgConstant {
|
|||||||
help: "Specify a memo string to include in the transaction.",
|
help: "Specify a memo string to include in the transaction.",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn memo_arg<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn memo_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(MEMO_ARG.name)
|
Arg::new(MEMO_ARG.name)
|
||||||
.long(MEMO_ARG.long)
|
.long(MEMO_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("MEMO")
|
.value_name("MEMO")
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
use {
|
use {
|
||||||
crate::{input_validators::*, offline::BLOCKHASH_ARG, ArgConstant},
|
crate::{input_validators::*, offline::BLOCKHASH_ARG, ArgConstant},
|
||||||
clap::{App, Arg},
|
clap::{Arg, Command},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const NONCE_ARG: ArgConstant<'static> = ArgConstant {
|
pub const NONCE_ARG: ArgConstant<'static> = ArgConstant {
|
||||||
@@ -18,22 +18,22 @@ pub const NONCE_AUTHORITY_ARG: ArgConstant<'static> = ArgConstant {
|
|||||||
help: "Provide the nonce authority keypair to use when signing a nonced transaction",
|
help: "Provide the nonce authority keypair to use when signing a nonced transaction",
|
||||||
};
|
};
|
||||||
|
|
||||||
fn nonce_arg<'a, 'b>() -> Arg<'a, 'b> {
|
fn nonce_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(NONCE_ARG.name)
|
Arg::new(NONCE_ARG.name)
|
||||||
.long(NONCE_ARG.long)
|
.long(NONCE_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("PUBKEY")
|
.value_name("PUBKEY")
|
||||||
.requires(BLOCKHASH_ARG.name)
|
.requires(BLOCKHASH_ARG.name)
|
||||||
.validator(is_valid_pubkey)
|
.validator(|s| is_valid_pubkey(s))
|
||||||
.help(NONCE_ARG.help)
|
.help(NONCE_ARG.help)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn nonce_authority_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(NONCE_AUTHORITY_ARG.name)
|
Arg::new(NONCE_AUTHORITY_ARG.name)
|
||||||
.long(NONCE_AUTHORITY_ARG.long)
|
.long(NONCE_AUTHORITY_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("KEYPAIR")
|
.value_name("KEYPAIR")
|
||||||
.validator(is_valid_signer)
|
.validator(|s| is_valid_signer(s))
|
||||||
.help(NONCE_AUTHORITY_ARG.help)
|
.help(NONCE_AUTHORITY_ARG.help)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ pub trait NonceArgs {
|
|||||||
fn nonce_args(self, global: bool) -> Self;
|
fn nonce_args(self, global: bool) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NonceArgs for App<'_, '_> {
|
impl NonceArgs for Command<'_> {
|
||||||
fn nonce_args(self, global: bool) -> Self {
|
fn nonce_args(self, global: bool) -> Self {
|
||||||
self.arg(nonce_arg().global(global)).arg(
|
self.arg(nonce_arg().global(global)).arg(
|
||||||
nonce_authority_arg()
|
nonce_authority_arg()
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
use {
|
use {
|
||||||
crate::{input_validators::*, ArgConstant},
|
crate::{input_validators::*, ArgConstant},
|
||||||
clap::{App, Arg},
|
clap::{Arg, Command},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const BLOCKHASH_ARG: ArgConstant<'static> = ArgConstant {
|
pub const BLOCKHASH_ARG: ArgConstant<'static> = ArgConstant {
|
||||||
@@ -27,36 +27,37 @@ pub const DUMP_TRANSACTION_MESSAGE: ArgConstant<'static> = ArgConstant {
|
|||||||
help: "Display the base64 encoded binary transaction message in sign-only mode",
|
help: "Display the base64 encoded binary transaction message in sign-only mode",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn blockhash_arg<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn blockhash_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(BLOCKHASH_ARG.name)
|
Arg::new(BLOCKHASH_ARG.name)
|
||||||
.long(BLOCKHASH_ARG.long)
|
.long(BLOCKHASH_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("BLOCKHASH")
|
.value_name("BLOCKHASH")
|
||||||
.validator(is_hash)
|
.validator(|s| is_hash(s))
|
||||||
.help(BLOCKHASH_ARG.help)
|
.help(BLOCKHASH_ARG.help)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sign_only_arg<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn sign_only_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(SIGN_ONLY_ARG.name)
|
Arg::new(SIGN_ONLY_ARG.name)
|
||||||
.long(SIGN_ONLY_ARG.long)
|
.long(SIGN_ONLY_ARG.long)
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.requires(BLOCKHASH_ARG.name)
|
.requires(BLOCKHASH_ARG.name)
|
||||||
.help(SIGN_ONLY_ARG.help)
|
.help(SIGN_ONLY_ARG.help)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signer_arg<'a, 'b>() -> Arg<'a, 'b> {
|
fn signer_arg<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(SIGNER_ARG.name)
|
Arg::new(SIGNER_ARG.name)
|
||||||
.long(SIGNER_ARG.long)
|
.long(SIGNER_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("PUBKEY=SIGNATURE")
|
.value_name("PUBKEY=SIGNATURE")
|
||||||
.validator(is_pubkey_sig)
|
.validator(|s| is_pubkey_sig(s))
|
||||||
.requires(BLOCKHASH_ARG.name)
|
.requires(BLOCKHASH_ARG.name)
|
||||||
.multiple(true)
|
.multiple_occurrences(true)
|
||||||
|
.multiple_values(true)
|
||||||
.help(SIGNER_ARG.help)
|
.help(SIGNER_ARG.help)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_transaction_message<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn dump_transaction_message<'a>() -> Arg<'a> {
|
||||||
Arg::with_name(DUMP_TRANSACTION_MESSAGE.name)
|
Arg::new(DUMP_TRANSACTION_MESSAGE.name)
|
||||||
.long(DUMP_TRANSACTION_MESSAGE.long)
|
.long(DUMP_TRANSACTION_MESSAGE.long)
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.requires(SIGN_ONLY_ARG.name)
|
.requires(SIGN_ONLY_ARG.name)
|
||||||
@@ -64,16 +65,16 @@ pub fn dump_transaction_message<'a, 'b>() -> Arg<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait ArgsConfig {
|
pub trait ArgsConfig {
|
||||||
fn blockhash_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
fn blockhash_arg<'a>(&self, arg: Arg<'a>) -> Arg<'a> {
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
fn sign_only_arg<'a>(&self, arg: Arg<'a>) -> Arg<'a> {
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
fn signer_arg<'a>(&self, arg: Arg<'a>) -> Arg<'a> {
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
fn dump_transaction_message_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
fn dump_transaction_message_arg<'a>(&self, arg: Arg<'a>) -> Arg<'a> {
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,7 @@ pub trait OfflineArgs {
|
|||||||
fn offline_args_config(self, config: &dyn ArgsConfig) -> Self;
|
fn offline_args_config(self, config: &dyn ArgsConfig) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OfflineArgs for App<'_, '_> {
|
impl OfflineArgs for Command<'_> {
|
||||||
fn offline_args_config(self, config: &dyn ArgsConfig) -> Self {
|
fn offline_args_config(self, config: &dyn ArgsConfig) -> Self {
|
||||||
self.arg(config.blockhash_arg(blockhash_arg()))
|
self.arg(config.blockhash_arg(blockhash_arg()))
|
||||||
.arg(config.sign_only_arg(sign_only_arg()))
|
.arg(config.sign_only_arg(sign_only_arg()))
|
||||||
|
Reference in New Issue
Block a user