Add --number argument
This commit is contained in:
parent
1824b5a2ce
commit
f14cf3ed1a
|
@ -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<String, CliValidatorsStakeByVersion>,
|
||||
#[serde(skip_serializing)]
|
||||
pub use_lamports_unit: bool,
|
||||
|
@ -377,7 +379,11 @@ 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} {}",
|
||||
" ",
|
||||
|
@ -389,7 +395,7 @@ impl fmt::Display for CliValidators {
|
|||
"Epoch Credits",
|
||||
"Version",
|
||||
"Active Stake",
|
||||
padding = padding
|
||||
padding = padding + 1
|
||||
))
|
||||
.bold();
|
||||
writeln!(f, "{}", header)?;
|
||||
|
@ -427,7 +433,9 @@ impl fmt::Display for CliValidators {
|
|||
}
|
||||
|
||||
for (i, validator) in sorted_validators.iter().enumerate() {
|
||||
if padding > 0 {
|
||||
write!(f, "{:padding$}", i + 1, padding = padding)?;
|
||||
}
|
||||
write_vote_account(
|
||||
f,
|
||||
validator,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<CliCommandInfo, CliError> {
|
||||
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<CliCommandInfo,
|
|||
use_lamports_unit,
|
||||
sort_order,
|
||||
reverse_sort,
|
||||
number_validators,
|
||||
},
|
||||
signers: vec![],
|
||||
})
|
||||
|
@ -1773,6 +1782,7 @@ pub fn process_show_validators(
|
|||
use_lamports_unit: bool,
|
||||
validators_sort_order: CliValidatorsSortOrder,
|
||||
validators_reverse_sort: bool,
|
||||
number_validators: bool,
|
||||
) -> 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,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue