clap-utils: Allow fine-tuning offline args

This commit is contained in:
Trent Nelson 2020-10-07 13:18:25 -06:00 committed by mergify[bot]
parent 71a308affd
commit 4feead323d
4 changed files with 34 additions and 16 deletions

View File

@ -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 {})
}
}

View File

@ -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()),
)

View File

@ -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())
)

View File

@ -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();