From f14cf3ed1af5f24ad0f30b743d8bbde0315d2a6c Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 19 Apr 2021 13:35:59 -0700 Subject: [PATCH] Add --number argument --- cli-output/src/cli_output.rs | 38 ++++++++++++++++++++++-------------- cli/src/cli.rs | 3 +++ cli/src/cluster_query.rs | 11 +++++++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index 2952ac22fc..6940f78241 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -326,6 +326,8 @@ pub struct CliValidators { pub validators_sort_order: CliValidatorsSortOrder, #[serde(skip_serializing)] pub validators_reverse_sort: bool, + #[serde(skip_serializing)] + pub number_validators: bool, pub stake_by_version: BTreeMap, #[serde(skip_serializing)] pub use_lamports_unit: bool, @@ -377,21 +379,25 @@ impl fmt::Display for CliValidators { ) } - let padding = ((self.validators.len() + 1) as f64).log10().floor() as usize + 1; + let padding = if self.number_validators { + ((self.validators.len() + 1) as f64).log10().floor() as usize + 1 + } else { + 0 + }; let header = style(format!( - "{:padding$} {:<44} {:<38} {} {} {} {:>11} {:^7} {}", - " ", - "Identity", - "Vote Account", - "Commission", - "Last Vote", - "Root Block", - "Epoch Credits", - "Version", - "Active Stake", - padding = padding - )) - .bold(); + "{:padding$} {:<44} {:<38} {} {} {} {:>11} {:^7} {}", + " ", + "Identity", + "Vote Account", + "Commission", + "Last Vote", + "Root Block", + "Epoch Credits", + "Version", + "Active Stake", + padding = padding + 1 + )) + .bold(); writeln!(f, "{}", header)?; let mut sorted_validators = self.validators.clone(); @@ -427,7 +433,9 @@ impl fmt::Display for CliValidators { } for (i, validator) in sorted_validators.iter().enumerate() { - write!(f, "{:padding$}", i + 1, padding = padding)?; + if padding > 0 { + write!(f, "{:padding$}", i + 1, padding = padding)?; + } write_vote_account( f, validator, diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 7a4cc41515..7b1f91983d 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -133,6 +133,7 @@ pub enum CliCommand { use_lamports_unit: bool, sort_order: CliValidatorsSortOrder, reverse_sort: bool, + number_validators: bool, }, Supply { print_accounts: bool, @@ -1385,12 +1386,14 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { use_lamports_unit, sort_order, reverse_sort, + number_validators, } => process_show_validators( &rpc_client, config, *use_lamports_unit, *sort_order, *reverse_sort, + *number_validators, ), CliCommand::Supply { print_accounts } => { process_supply(&rpc_client, config, *print_accounts) diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index e108485cb6..7afde55502 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -350,6 +350,13 @@ impl ClusterQuerySubCommands for App<'_, '_> { .takes_value(false) .help("Display balance in lamports instead of SOL"), ) + .arg( + Arg::with_name("number") + .long("number") + .short("n") + .takes_value(false) + .help("Number the validators"), + ) .arg( Arg::with_name("reverse") .long("reverse") @@ -606,6 +613,7 @@ pub fn parse_show_stakes( pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result { let use_lamports_unit = matches.is_present("lamports"); + let number_validators = matches.is_present("number"); let reverse_sort = matches.is_present("reverse"); let sort_order = match value_t_or_exit!(matches, "sort", String).as_str() { @@ -625,6 +633,7 @@ pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result ProcessResult { let epoch_info = rpc_client.get_epoch_info()?; let vote_accounts = rpc_client.get_vote_accounts()?; @@ -1859,6 +1869,7 @@ pub fn process_show_validators( .collect(), validators_sort_order, validators_reverse_sort, + number_validators, stake_by_version, use_lamports_unit, };