From ffbbdd46e832ddc3c507599b537cfcfd1c9e997e Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sat, 2 May 2020 13:06:35 -0700 Subject: [PATCH] Add clap.rs default for --commitment (#9859) --- clap-utils/src/commitment.rs | 3 ++- cli/src/cluster_query.rs | 33 +++++++++------------------------ cli/src/vote.rs | 3 +-- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/clap-utils/src/commitment.rs b/clap-utils/src/commitment.rs index b7e0fa4cf7..566a14c066 100644 --- a/clap-utils/src/commitment.rs +++ b/clap-utils/src/commitment.rs @@ -11,7 +11,8 @@ pub fn commitment_arg<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name(COMMITMENT_ARG.name) .long(COMMITMENT_ARG.long) .takes_value(true) - .possible_values(&["default", "max", "recent", "root"]) + .possible_values(&["recent", "root", "max"]) + .default_value("recent") .value_name("COMMITMENT_LEVEL") .help(COMMITMENT_ARG.help) } diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index ff3cbf1c01..23d5c4c773 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -166,14 +166,7 @@ impl ClusterQuerySubCommands for App<'_, '_> { .default_value("15") .help("Wait up to timeout seconds for transaction confirmation"), ) - .arg( - Arg::with_name(COMMITMENT_ARG.name) - .long(COMMITMENT_ARG.long) - .takes_value(true) - .possible_values(&["default", "max", "recent", "root"]) - .value_name("COMMITMENT_LEVEL") - .help("Wait until the transaction is confirmed at selected commitment level"), - ), + .arg(commitment_arg()), ) .subcommand( SubCommand::with_name("live-slots") @@ -272,8 +265,7 @@ pub fn parse_catchup( ) -> Result { let node_pubkey = pubkey_of_signer(matches, "node_pubkey", wallet_manager)?.unwrap(); let node_json_rpc_url = value_t!(matches, "node_json_rpc_url", String).ok(); - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); let follow = matches.is_present("follow"); Ok(CliCommandInfo { command: CliCommand::Catchup { @@ -299,8 +291,7 @@ pub fn parse_cluster_ping( None }; let timeout = Duration::from_secs(value_t_or_exit!(matches, "timeout", u64)); - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::Ping { lamports, @@ -327,8 +318,7 @@ pub fn parse_get_block_time(matches: &ArgMatches<'_>) -> Result) -> Result { - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::GetEpochInfo { commitment_config }, signers: vec![], @@ -336,8 +326,7 @@ pub fn parse_get_epoch_info(matches: &ArgMatches<'_>) -> Result) -> Result { - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::GetSlot { commitment_config }, signers: vec![], @@ -345,8 +334,7 @@ pub fn parse_get_slot(matches: &ArgMatches<'_>) -> Result) -> Result { - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::GetEpoch { commitment_config }, signers: vec![], @@ -354,8 +342,7 @@ pub fn parse_get_epoch(matches: &ArgMatches<'_>) -> Result) -> Result { - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::TotalSupply { commitment_config }, signers: vec![], @@ -363,8 +350,7 @@ pub fn parse_total_supply(matches: &ArgMatches<'_>) -> Result) -> Result { - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::GetTransactionCount { commitment_config }, signers: vec![], @@ -390,8 +376,7 @@ pub fn parse_show_stakes( pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result { let use_lamports_unit = matches.is_present("lamports"); - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::ShowValidators { diff --git a/cli/src/vote.rs b/cli/src/vote.rs index 192b1b0613..30790151c4 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -315,8 +315,7 @@ pub fn parse_vote_get_account_command( let vote_account_pubkey = pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap(); let use_lamports_unit = matches.is_present("lamports"); - let commitment_config = - commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent); + let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap(); Ok(CliCommandInfo { command: CliCommand::ShowVoteAccount { pubkey: vote_account_pubkey,