clap-utils: Allow nonce/offline args to be global

This commit is contained in:
Trent Nelson 2020-09-28 20:59:37 -06:00 committed by Trent Nelson
parent 36d55c0667
commit 972619edb4
5 changed files with 35 additions and 30 deletions

View File

@ -36,12 +36,15 @@ pub fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
} }
pub trait NonceArgs { pub trait NonceArgs {
fn nonce_args(self) -> Self; fn nonce_args(self, global: bool) -> Self;
} }
impl NonceArgs for App<'_, '_> { impl NonceArgs for App<'_, '_> {
fn nonce_args(self) -> Self { fn nonce_args(self, global: bool) -> Self {
self.arg(nonce_arg()) self.arg(nonce_arg().global(global)).arg(
.arg(nonce_authority_arg().requires(NONCE_ARG.name)) nonce_authority_arg()
.requires(NONCE_ARG.name)
.global(global),
)
} }
} }

View File

@ -48,13 +48,13 @@ fn signer_arg<'a, 'b>() -> Arg<'a, 'b> {
} }
pub trait OfflineArgs { pub trait OfflineArgs {
fn offline_args(self) -> Self; fn offline_args(self, global: bool) -> Self;
} }
impl OfflineArgs for App<'_, '_> { impl OfflineArgs for App<'_, '_> {
fn offline_args(self) -> Self { fn offline_args(self, global: bool) -> Self {
self.arg(blockhash_arg()) self.arg(blockhash_arg().global(global))
.arg(sign_only_arg()) .arg(sign_only_arg().global(global))
.arg(signer_arg()) .arg(signer_arg().global(global))
} }
} }

View File

@ -2132,8 +2132,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
) )
.subcommand( .subcommand(
SubCommand::with_name("resolve-signer") SubCommand::with_name("resolve-signer")
@ -2179,8 +2179,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()), .arg(fee_payer_arg()),
) )
.subcommand( .subcommand(

View File

@ -154,8 +154,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(
@ -183,8 +183,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(
@ -213,8 +213,8 @@ impl StakeSubCommands for App<'_, '_> {
) )
.arg(stake_authority_arg()) .arg(stake_authority_arg())
.arg(withdraw_authority_arg()) .arg(withdraw_authority_arg())
.offline_args() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(
@ -228,8 +228,8 @@ impl StakeSubCommands for App<'_, '_> {
"Stake account to be deactivated. ") "Stake account to be deactivated. ")
) )
.arg(stake_authority_arg()) .arg(stake_authority_arg())
.offline_args() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(
@ -268,8 +268,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(
@ -290,8 +290,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(
@ -321,8 +321,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
.arg( .arg(
Arg::with_name("custodian") Arg::with_name("custodian")
@ -376,8 +376,8 @@ 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() .offline_args(false)
.nonce_args() .nonce_args(false)
.arg(fee_payer_arg()) .arg(fee_payer_arg())
) )
.subcommand( .subcommand(

View File

@ -177,7 +177,9 @@ mod tests {
#[test] #[test]
fn test_blockhash_query_new_from_matches_ok() { fn test_blockhash_query_new_from_matches_ok() {
let test_commands = App::new("blockhash_query_test").nonce_args().offline_args(); let test_commands = App::new("blockhash_query_test")
.nonce_args(false)
.offline_args(false);
let blockhash = hash(&[1u8]); let blockhash = hash(&[1u8]);
let blockhash_string = blockhash.to_string(); let blockhash_string = blockhash.to_string();