clap-utils: Allow fine-tuning offline args
This commit is contained in:
committed by
mergify[bot]
parent
71a308affd
commit
4feead323d
@ -47,14 +47,32 @@ fn signer_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|||||||
.help(SIGNER_ARG.help)
|
.help(SIGNER_ARG.help)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait ArgsConfig {
|
||||||
|
fn blockhash_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
||||||
|
arg
|
||||||
|
}
|
||||||
|
fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
||||||
|
arg
|
||||||
|
}
|
||||||
|
fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
|
||||||
|
arg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait OfflineArgs {
|
pub trait OfflineArgs {
|
||||||
fn offline_args(self, global: bool) -> Self;
|
fn offline_args(self) -> Self;
|
||||||
|
fn offline_args_config(self, config: &dyn ArgsConfig) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OfflineArgs for App<'_, '_> {
|
impl OfflineArgs for App<'_, '_> {
|
||||||
fn offline_args(self, global: bool) -> Self {
|
fn offline_args_config(self, config: &dyn ArgsConfig) -> Self {
|
||||||
self.arg(blockhash_arg().global(global))
|
self.arg(config.blockhash_arg(blockhash_arg()))
|
||||||
.arg(sign_only_arg().global(global))
|
.arg(config.sign_only_arg(sign_only_arg()))
|
||||||
.arg(signer_arg().global(global))
|
.arg(config.signer_arg(signer_arg()))
|
||||||
|
}
|
||||||
|
fn offline_args(self) -> Self {
|
||||||
|
struct NullArgsConfig {}
|
||||||
|
impl ArgsConfig for NullArgsConfig {}
|
||||||
|
self.offline_args_config(&NullArgsConfig {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2220,7 +2220,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
|||||||
.required(true)
|
.required(true)
|
||||||
.help("The amount to send, in SOL; accepts keyword ALL"),
|
.help("The amount to send, in SOL; accepts keyword ALL"),
|
||||||
)
|
)
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
@ -2267,7 +2267,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
|||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Return signature immediately after submitting the transaction, instead of waiting for confirmations"),
|
.help("Return signature immediately after submitting the transaction, instead of waiting for confirmations"),
|
||||||
)
|
)
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg()),
|
.arg(fee_payer_arg()),
|
||||||
)
|
)
|
||||||
|
@ -154,7 +154,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
.validator(is_valid_signer)
|
.validator(is_valid_signer)
|
||||||
.help("Source account of funds [default: cli config keypair]"),
|
.help("Source account of funds [default: cli config keypair]"),
|
||||||
)
|
)
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
@ -183,7 +183,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
"The vote account to which the stake will be delegated")
|
"The vote account to which the stake will be delegated")
|
||||||
)
|
)
|
||||||
.arg(stake_authority_arg())
|
.arg(stake_authority_arg())
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
@ -213,7 +213,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
)
|
)
|
||||||
.arg(stake_authority_arg())
|
.arg(stake_authority_arg())
|
||||||
.arg(withdraw_authority_arg())
|
.arg(withdraw_authority_arg())
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
@ -228,7 +228,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
"Stake account to be deactivated. ")
|
"Stake account to be deactivated. ")
|
||||||
)
|
)
|
||||||
.arg(stake_authority_arg())
|
.arg(stake_authority_arg())
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
@ -268,7 +268,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
.help("Seed for address generation; if specified, the resulting account will be at a derived address of the SPLIT STAKE ACCOUNT pubkey")
|
.help("Seed for address generation; if specified, the resulting account will be at a derived address of the SPLIT STAKE ACCOUNT pubkey")
|
||||||
)
|
)
|
||||||
.arg(stake_authority_arg())
|
.arg(stake_authority_arg())
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
@ -290,7 +290,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
"Source stake account for the merge. If successful, this stake account will no longer exist after the merge")
|
"Source stake account for the merge. If successful, this stake account will no longer exist after the merge")
|
||||||
)
|
)
|
||||||
.arg(stake_authority_arg())
|
.arg(stake_authority_arg())
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
@ -321,7 +321,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
.help("The amount to withdraw from the stake account, in SOL")
|
.help("The amount to withdraw from the stake account, in SOL")
|
||||||
)
|
)
|
||||||
.arg(withdraw_authority_arg())
|
.arg(withdraw_authority_arg())
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
.arg(
|
.arg(
|
||||||
@ -376,7 +376,7 @@ impl StakeSubCommands for App<'_, '_> {
|
|||||||
.validator(is_valid_signer)
|
.validator(is_valid_signer)
|
||||||
.help("Keypair of the existing custodian [default: cli config pubkey]")
|
.help("Keypair of the existing custodian [default: cli config pubkey]")
|
||||||
)
|
)
|
||||||
.offline_args(false)
|
.offline_args()
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.arg(fee_payer_arg())
|
.arg(fee_payer_arg())
|
||||||
)
|
)
|
||||||
|
@ -179,7 +179,7 @@ mod tests {
|
|||||||
fn test_blockhash_query_new_from_matches_ok() {
|
fn test_blockhash_query_new_from_matches_ok() {
|
||||||
let test_commands = App::new("blockhash_query_test")
|
let test_commands = App::new("blockhash_query_test")
|
||||||
.nonce_args(false)
|
.nonce_args(false)
|
||||||
.offline_args(false);
|
.offline_args();
|
||||||
let blockhash = hash(&[1u8]);
|
let blockhash = hash(&[1u8]);
|
||||||
let blockhash_string = blockhash.to_string();
|
let blockhash_string = blockhash.to_string();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user