From 4feead323d8ddb757d6c2a99f8be854ad7044667 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Wed, 7 Oct 2020 13:18:25 -0600 Subject: [PATCH] clap-utils: Allow fine-tuning offline args --- clap-utils/src/offline.rs | 28 +++++++++++++++++++++++----- cli/src/cli.rs | 4 ++-- cli/src/stake.rs | 16 ++++++++-------- client/src/blockhash_query.rs | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/clap-utils/src/offline.rs b/clap-utils/src/offline.rs index f6cc120352..514e49fa7c 100644 --- a/clap-utils/src/offline.rs +++ b/clap-utils/src/offline.rs @@ -47,14 +47,32 @@ fn signer_arg<'a, 'b>() -> Arg<'a, 'b> { .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 { - 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<'_, '_> { - fn offline_args(self, global: bool) -> Self { - self.arg(blockhash_arg().global(global)) - .arg(sign_only_arg().global(global)) - .arg(signer_arg().global(global)) + fn offline_args_config(self, config: &dyn ArgsConfig) -> Self { + self.arg(config.blockhash_arg(blockhash_arg())) + .arg(config.sign_only_arg(sign_only_arg())) + .arg(config.signer_arg(signer_arg())) + } + fn offline_args(self) -> Self { + struct NullArgsConfig {} + impl ArgsConfig for NullArgsConfig {} + self.offline_args_config(&NullArgsConfig {}) } } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index d41d165531..fae1c4492d 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -2220,7 +2220,7 @@ 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(false) + .offline_args() .nonce_args(false) ) .subcommand( @@ -2267,7 +2267,7 @@ 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(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()), ) diff --git a/cli/src/stake.rs b/cli/src/stake.rs index a086640aee..a5e4051c58 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -154,7 +154,7 @@ impl StakeSubCommands for App<'_, '_> { .validator(is_valid_signer) .help("Source account of funds [default: cli config keypair]"), ) - .offline_args(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()) ) @@ -183,7 +183,7 @@ impl StakeSubCommands for App<'_, '_> { "The vote account to which the stake will be delegated") ) .arg(stake_authority_arg()) - .offline_args(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()) ) @@ -213,7 +213,7 @@ impl StakeSubCommands for App<'_, '_> { ) .arg(stake_authority_arg()) .arg(withdraw_authority_arg()) - .offline_args(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()) ) @@ -228,7 +228,7 @@ impl StakeSubCommands for App<'_, '_> { "Stake account to be deactivated. ") ) .arg(stake_authority_arg()) - .offline_args(false) + .offline_args() .nonce_args(false) .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") ) .arg(stake_authority_arg()) - .offline_args(false) + .offline_args() .nonce_args(false) .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") ) .arg(stake_authority_arg()) - .offline_args(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()) ) @@ -321,7 +321,7 @@ impl StakeSubCommands for App<'_, '_> { .help("The amount to withdraw from the stake account, in SOL") ) .arg(withdraw_authority_arg()) - .offline_args(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()) .arg( @@ -376,7 +376,7 @@ impl StakeSubCommands for App<'_, '_> { .validator(is_valid_signer) .help("Keypair of the existing custodian [default: cli config pubkey]") ) - .offline_args(false) + .offline_args() .nonce_args(false) .arg(fee_payer_arg()) ) diff --git a/client/src/blockhash_query.rs b/client/src/blockhash_query.rs index abaeec7075..1cf40056a2 100644 --- a/client/src/blockhash_query.rs +++ b/client/src/blockhash_query.rs @@ -179,7 +179,7 @@ mod tests { fn test_blockhash_query_new_from_matches_ok() { let test_commands = App::new("blockhash_query_test") .nonce_args(false) - .offline_args(false); + .offline_args(); let blockhash = hash(&[1u8]); let blockhash_string = blockhash.to_string();