Add --all option to bounds, to display all non-empty slots

This commit is contained in:
Michael Vines
2019-12-20 15:22:45 -07:00
parent e35bd54d99
commit 19215ddaa2

View File

@ -436,7 +436,14 @@ fn main() {
) )
.subcommand( .subcommand(
SubCommand::with_name("bounds") SubCommand::with_name("bounds")
.about("Print lowest and highest non-empty slots. Note: This ignores gaps in slots") .about("Print lowest and highest non-empty slots. Note that there may be empty slots within the bounds")
.arg(
Arg::with_name("all")
.long("all")
.takes_value(false)
.required(false)
.help("Additionally print all the non-empty slots within the bounds"),
)
) )
.subcommand( .subcommand(
SubCommand::with_name("json") SubCommand::with_name("json")
@ -719,28 +726,32 @@ fn main() {
} }
}); });
} }
("bounds", _) => match blocktree.slot_meta_iterator(0) { ("bounds", Some(args_matches)) => {
Ok(metas) => { match blocktree.slot_meta_iterator(0) {
println!("Collecting Ledger information..."); Ok(metas) => {
let slots: Vec<_> = metas.map(|(slot, _)| slot).collect(); let all = args_matches.is_present("all");
if slots.is_empty() {
println!("Ledger is empty. No slots found."); println!("Collecting Ledger information...");
} else { let slots: Vec<_> = metas.map(|(slot, _)| slot).collect();
let first = slots.first().unwrap(); if slots.is_empty() {
let last = slots.last().unwrap_or_else(|| first); println!("Ledger is empty. No slots found.");
if first != last {
println!(
"Ledger contains some data for slots {:?} to {:?}",
first, last
);
} else { } else {
println!("Ledger only contains some data for slot {:?}", first); let first = slots.first().unwrap();
let last = slots.last().unwrap_or_else(|| first);
if first != last {
println!("Ledger contains data from slots {:?} to {:?}", first, last);
if all {
println!("Non-empty slots: {:?}", slots);
}
} else {
println!("Ledger only contains some data for slot {:?}", first);
}
} }
} }
} Err(err) => {
Err(err) => { eprintln!("Unable to read the Ledger: {:?}", err);
eprintln!("Unable to read the Ledger: {:?}", err); exit(1);
exit(1); }
} }
}, },
("", _) => { ("", _) => {