Enhance ledger-tool

Add a command-line argument (min-hashes) to restrict the entries
processed by ledger-tool.  For example, --min-hashes 1 will strip
"empty" Entries, i.e. those with num_hashes = 0.

Add basic ledger tool test
This commit is contained in:
Kevin Hart
2018-12-07 20:44:59 -08:00
committed by Greg Fitzgerald
parent b26906df1b
commit 84cc240f34
4 changed files with 164 additions and 0 deletions

View File

@@ -25,6 +25,14 @@ fn main() {
.takes_value(true)
.help("Limit to at most the first NUM entries in ledger\n (only applies to verify, print, json commands)"),
)
.arg(
Arg::with_name("min-hashes")
.short("h")
.long("min-hashes")
.value_name("NUM")
.takes_value(true)
.help("Skip entries with fewer than NUM hashes\n (only applies to print and json commands)"),
)
.arg(
Arg::with_name("precheck")
.short("p")
@@ -64,6 +72,13 @@ fn main() {
None => <usize>::max_value(),
};
let min_hashes = match matches.value_of("min-hashes") {
Some(hashes) => hashes
.parse()
.expect("please pass a number for --min-hashes"),
None => 0,
} as u64;
match matches.subcommand() {
("print", _) => {
let entries = match read_ledger(ledger_path, true) {
@@ -78,6 +93,9 @@ fn main() {
break;
}
let entry = entry.unwrap();
if entry.num_hashes < min_hashes {
continue;
}
println!("{:?}", entry);
}
}
@@ -88,6 +106,9 @@ fn main() {
break;
}
let entry = entry.unwrap();
if entry.num_hashes < min_hashes {
continue;
}
serde_json::to_writer(stdout(), &entry).expect("serialize");
stdout().write_all(b",\n").expect("newline");
}