cli: Add clap.rs default for --commitment (bp #9859) (#9860)

automerge
This commit is contained in:
mergify[bot]
2020-05-02 17:58:31 -07:00
committed by GitHub
parent 2e5cc41945
commit 20fe24f348
3 changed files with 10 additions and 23 deletions

View File

@ -11,7 +11,8 @@ pub fn commitment_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name(COMMITMENT_ARG.name) Arg::with_name(COMMITMENT_ARG.name)
.long(COMMITMENT_ARG.long) .long(COMMITMENT_ARG.long)
.takes_value(true) .takes_value(true)
.possible_values(&["default", "max", "recent", "root"]) .possible_values(&["recent", "root", "max"])
.default_value("recent")
.value_name("COMMITMENT_LEVEL") .value_name("COMMITMENT_LEVEL")
.help(COMMITMENT_ARG.help) .help(COMMITMENT_ARG.help)
} }

View File

@ -155,14 +155,7 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.default_value("15") .default_value("15")
.help("Wait up to timeout seconds for transaction confirmation"), .help("Wait up to timeout seconds for transaction confirmation"),
) )
.arg( .arg(commitment_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"),
),
) )
.subcommand( .subcommand(
SubCommand::with_name("live-slots") SubCommand::with_name("live-slots")
@ -252,8 +245,7 @@ pub fn parse_cluster_ping(
None None
}; };
let timeout = Duration::from_secs(value_t_or_exit!(matches, "timeout", u64)); let timeout = Duration::from_secs(value_t_or_exit!(matches, "timeout", u64));
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::Ping { command: CliCommand::Ping {
lamports, lamports,
@ -280,8 +272,7 @@ pub fn parse_get_block_time(matches: &ArgMatches<'_>) -> Result<CliCommandInfo,
} }
pub fn parse_get_epoch_info(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_get_epoch_info(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::GetEpochInfo { commitment_config }, command: CliCommand::GetEpochInfo { commitment_config },
signers: vec![], signers: vec![],
@ -289,8 +280,7 @@ pub fn parse_get_epoch_info(matches: &ArgMatches<'_>) -> Result<CliCommandInfo,
} }
pub fn parse_get_slot(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_get_slot(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::GetSlot { commitment_config }, command: CliCommand::GetSlot { commitment_config },
signers: vec![], signers: vec![],
@ -298,8 +288,7 @@ pub fn parse_get_slot(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliErr
} }
pub fn parse_get_epoch(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_get_epoch(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::GetEpoch { commitment_config }, command: CliCommand::GetEpoch { commitment_config },
signers: vec![], signers: vec![],
@ -307,8 +296,7 @@ pub fn parse_get_epoch(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliEr
} }
pub fn parse_get_transaction_count(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_get_transaction_count(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::GetTransactionCount { commitment_config }, command: CliCommand::GetTransactionCount { commitment_config },
signers: vec![], signers: vec![],
@ -334,8 +322,7 @@ pub fn parse_show_stakes(
pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let use_lamports_unit = matches.is_present("lamports"); let use_lamports_unit = matches.is_present("lamports");
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::ShowValidators { command: CliCommand::ShowValidators {

View File

@ -319,8 +319,7 @@ pub fn parse_vote_get_account_command(
let vote_account_pubkey = let vote_account_pubkey =
pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap(); pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
let use_lamports_unit = matches.is_present("lamports"); let use_lamports_unit = matches.is_present("lamports");
let commitment_config = let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
commitment_of(matches, COMMITMENT_ARG.long).unwrap_or_else(CommitmentConfig::recent);
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::ShowVoteAccount { command: CliCommand::ShowVoteAccount {
pubkey: vote_account_pubkey, pubkey: vote_account_pubkey,