Browse Source

Improve command line options

taddr
Aditya Kulkarni 5 years ago
parent
commit
f02db4a8bb
  1. 37
      cli/src/main.rs
  2. 2
      lib/src/pdf.rs

37
cli/src/main.rs

@ -4,6 +4,8 @@ extern crate zecpaperlib;
use clap::{Arg, App};
use zecpaperlib::paper::*;
use zecpaperlib::pdf;
use std::io;
use std::io::prelude::*;
fn main() {
let matches = App::new("zecpaperwaller")
@ -19,7 +21,7 @@ fn main() {
.help("What format to generate the output in")
.takes_value(true)
.value_name("FORMAT")
.possible_values(&["png", "pdf", "json"])
.possible_values(&["pdf", "json"])
.default_value("json"))
.arg(Arg::with_name("output")
.short("o")
@ -40,12 +42,39 @@ fn main() {
let testnet: bool = matches.is_present("testnet");
if !testnet {
eprint!("Mainnet addresses are not supported yet. Please re-run with --testnet\n");
eprintln!("Mainnet addresses are not supported yet. Please re-run with --testnet");
return;
}
let filename = matches.value_of("output");
let format = matches.value_of("format").unwrap();
// Writing to PDF requires a filename
if format == "pdf" && filename.is_none() {
eprintln!("Need an output file name when writing to PDF");
return;
}
let num_addresses = matches.value_of("z_addresses").unwrap().parse::<u32>().unwrap();
print!("Generating {} Sapling addresses.........", num_addresses);
io::stdout().flush().ok();
let addresses = generate_wallet(testnet, num_addresses);
println!("{}", addresses);
pdf::save_to_pdf(&addresses, "test_working.pdf");
println!("[OK]");
// If the default format is present, write to the console if the filename is absent
if format == "json" {
if filename.is_none() {
println!("{}", addresses);
} else {
std::fs::write(filename.unwrap(), addresses).expect("Couldn't write to file!");
println!("Wrote {:?} as a plaintext file", filename);
}
} else if format == "pdf" {
// We already know the output file name was specified
print!("Writing {:?} as a PDF file...", filename.unwrap());
io::stdout().flush().ok();
pdf::save_to_pdf(&addresses, filename.unwrap());
println!("[OK]");
}
}

2
lib/src/pdf.rs

@ -225,7 +225,7 @@ mod tests {
// Test random combinations of block size and spaces to ensure that
// the string is always preserved
for m in 2..100 {
for m in 1..100 {
for b in 1..40 {
assert_eq!(split_to_max(addr, m, b).join(" ").replace(" ", ""), addr);
assert_eq!(split_to_max(pk, m, b).join(" ").replace(" ", ""), pk);

Loading…
Cancel
Save