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,8 +726,11 @@ fn main() {
} }
}); });
} }
("bounds", _) => match blocktree.slot_meta_iterator(0) { ("bounds", Some(args_matches)) => {
match blocktree.slot_meta_iterator(0) {
Ok(metas) => { Ok(metas) => {
let all = args_matches.is_present("all");
println!("Collecting Ledger information..."); println!("Collecting Ledger information...");
let slots: Vec<_> = metas.map(|(slot, _)| slot).collect(); let slots: Vec<_> = metas.map(|(slot, _)| slot).collect();
if slots.is_empty() { if slots.is_empty() {
@ -729,10 +739,10 @@ fn main() {
let first = slots.first().unwrap(); let first = slots.first().unwrap();
let last = slots.last().unwrap_or_else(|| first); let last = slots.last().unwrap_or_else(|| first);
if first != last { if first != last {
println!( println!("Ledger contains data from slots {:?} to {:?}", first, last);
"Ledger contains some data for slots {:?} to {:?}", if all {
first, last println!("Non-empty slots: {:?}", slots);
); }
} else { } else {
println!("Ledger only contains some data for slot {:?}", first); println!("Ledger only contains some data for slot {:?}", first);
} }
@ -742,6 +752,7 @@ fn main() {
eprintln!("Unable to read the Ledger: {:?}", err); eprintln!("Unable to read the Ledger: {:?}", err);
exit(1); exit(1);
} }
}
}, },
("", _) => { ("", _) => {
eprintln!("{}", matches.usage()); eprintln!("{}", matches.usage());