From 972619edb40fb2be7f9be527d9a68811c076b74f Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Mon, 28 Sep 2020 20:59:37 -0600 Subject: [PATCH] clap-utils: Allow nonce/offline args to be global --- clap-utils/src/nonce.rs | 11 +++++++---- clap-utils/src/offline.rs | 10 +++++----- cli/src/cli.rs | 8 ++++---- cli/src/stake.rs | 32 ++++++++++++++++---------------- client/src/blockhash_query.rs | 4 +++- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/clap-utils/src/nonce.rs b/clap-utils/src/nonce.rs index fd5ff2ef71..2979135b26 100644 --- a/clap-utils/src/nonce.rs +++ b/clap-utils/src/nonce.rs @@ -36,12 +36,15 @@ pub fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> { } pub trait NonceArgs { - fn nonce_args(self) -> Self; + fn nonce_args(self, global: bool) -> Self; } impl NonceArgs for App<'_, '_> { - fn nonce_args(self) -> Self { - self.arg(nonce_arg()) - .arg(nonce_authority_arg().requires(NONCE_ARG.name)) + fn nonce_args(self, global: bool) -> Self { + self.arg(nonce_arg().global(global)).arg( + nonce_authority_arg() + .requires(NONCE_ARG.name) + .global(global), + ) } } diff --git a/clap-utils/src/offline.rs b/clap-utils/src/offline.rs index 81dce6ecf4..f6cc120352 100644 --- a/clap-utils/src/offline.rs +++ b/clap-utils/src/offline.rs @@ -48,13 +48,13 @@ fn signer_arg<'a, 'b>() -> Arg<'a, 'b> { } pub trait OfflineArgs { - fn offline_args(self) -> Self; + fn offline_args(self, global: bool) -> Self; } impl OfflineArgs for App<'_, '_> { - fn offline_args(self) -> Self { - self.arg(blockhash_arg()) - .arg(sign_only_arg()) - .arg(signer_arg()) + fn offline_args(self, global: bool) -> Self { + self.arg(blockhash_arg().global(global)) + .arg(sign_only_arg().global(global)) + .arg(signer_arg().global(global)) } } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 2990b9ba6d..d1c0ff24f3 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -2132,8 +2132,8 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' .required(true) .help("The amount to send, in SOL; accepts keyword ALL"), ) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) ) .subcommand( 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) .help("Return signature immediately after submitting the transaction, instead of waiting for confirmations"), ) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()), ) .subcommand( diff --git a/cli/src/stake.rs b/cli/src/stake.rs index e39474133b..a086640aee 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -154,8 +154,8 @@ impl StakeSubCommands for App<'_, '_> { .validator(is_valid_signer) .help("Source account of funds [default: cli config keypair]"), ) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .subcommand( @@ -183,8 +183,8 @@ impl StakeSubCommands for App<'_, '_> { "The vote account to which the stake will be delegated") ) .arg(stake_authority_arg()) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .subcommand( @@ -213,8 +213,8 @@ impl StakeSubCommands for App<'_, '_> { ) .arg(stake_authority_arg()) .arg(withdraw_authority_arg()) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .subcommand( @@ -228,8 +228,8 @@ impl StakeSubCommands for App<'_, '_> { "Stake account to be deactivated. ") ) .arg(stake_authority_arg()) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .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") ) .arg(stake_authority_arg()) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .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") ) .arg(stake_authority_arg()) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .subcommand( @@ -321,8 +321,8 @@ impl StakeSubCommands for App<'_, '_> { .help("The amount to withdraw from the stake account, in SOL") ) .arg(withdraw_authority_arg()) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) .arg( Arg::with_name("custodian") @@ -376,8 +376,8 @@ impl StakeSubCommands for App<'_, '_> { .validator(is_valid_signer) .help("Keypair of the existing custodian [default: cli config pubkey]") ) - .offline_args() - .nonce_args() + .offline_args(false) + .nonce_args(false) .arg(fee_payer_arg()) ) .subcommand( diff --git a/client/src/blockhash_query.rs b/client/src/blockhash_query.rs index dae1b79a60..abaeec7075 100644 --- a/client/src/blockhash_query.rs +++ b/client/src/blockhash_query.rs @@ -177,7 +177,9 @@ mod tests { #[test] 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_string = blockhash.to_string();