diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/geniza-register.rs | 54 | ||||
-rw-r--r-- | src/bin/geniza-sleep.rs | 34 |
2 files changed, 28 insertions, 60 deletions
diff --git a/src/bin/geniza-register.rs b/src/bin/geniza-register.rs deleted file mode 100644 index a328bbc..0000000 --- a/src/bin/geniza-register.rs +++ /dev/null @@ -1,54 +0,0 @@ - -#[macro_use] -extern crate error_chain; -extern crate clap; -extern crate env_logger; -extern crate geniza; - -// TODO: more careful import -use geniza::*; -use std::path::Path; -use clap::{App, SubCommand}; - -fn run() -> Result<()> { - - env_logger::init().unwrap(); - - let matches = App::new("geniza-register") - .version(env!("CARGO_PKG_VERSION")) - .subcommand(SubCommand::with_name("info") - .about("Reads a SLEEP dir register and shows some basic metadata") - .arg_from_usage("<DIR> 'directory containing files'") - .arg_from_usage("<prefix> 'prefix for each data file'")) - .subcommand(SubCommand::with_name("create") - .about("Creates an SLEEP directory register (with header)") - .arg_from_usage("<DIR> 'directory containing files'") - .arg_from_usage("<prefix> 'prefix for each data file'")) - .get_matches(); - - - match matches.subcommand() { - ("info", Some(subm)) => { - let dir = Path::new(subm.value_of("DIR").unwrap()); - let prefix = subm.value_of("prefix").unwrap(); - let mut sdr = SleepDirRegister::open(dir, prefix, false)?; - //debug!(println!("{:?}", sdr)); - println!("Entry count: {}", sdr.len()?); - println!("Total size (bytes): {}", sdr.len_bytes()?); - }, - ("create", Some(subm)) => { - let dir = Path::new(subm.value_of("DIR").unwrap()); - let prefix = subm.value_of("prefix").unwrap(); - SleepDirRegister::create(dir, prefix)?; - println!("Done!"); - }, - _ => { - println!("Missing or unimplemented command!"); - println!("{}", matches.usage()); - ::std::process::exit(-1); - }, - } - Ok(()) -} - -quick_main!(run); diff --git a/src/bin/geniza-sleep.rs b/src/bin/geniza-sleep.rs index 10fc16b..17ff91b 100644 --- a/src/bin/geniza-sleep.rs +++ b/src/bin/geniza-sleep.rs @@ -18,22 +18,44 @@ fn run() -> Result<()> { let matches = App::new("geniza-sleep") .version(env!("CARGO_PKG_VERSION")) .subcommand(SubCommand::with_name("info") - .about("Reads a SLEEP file and shows some basic metadata") - .arg_from_usage("<FILE> 'SLEEP file to read'")) + .about("Reads a SLEEP dir register and shows some basic metadata") + .arg_from_usage("<DIR> 'directory containing files'") + .arg_from_usage("<prefix> 'prefix for each data file'")) .subcommand(SubCommand::with_name("create") - .about("Creates an empty SLEEP file (with header)") + .about("Creates an SLEEP directory register (with header)") + .arg_from_usage("<DIR> 'directory containing files'") + .arg_from_usage("<prefix> 'prefix for each data file'")) + .subcommand(SubCommand::with_name("file-info") + .about("Reads a single SLEEP file and shows some basic metadata") + .arg_from_usage("<FILE> 'SLEEP file to read'")) + .subcommand(SubCommand::with_name("file-create") + .about("Creates an empty single SLEEP file (with header)") .arg_from_usage("<FILE> 'SLEEP file to write (can't exist)'") .arg_from_usage("<magic> 'Magic word to use (eg, 0x5025700)'") .arg_from_usage("<entry_size> 'Size of each entry (bytes)'") .arg_from_usage("<algo_name> 'Name of algorithm (empty string for none)'")) .subcommand(SubCommand::with_name("read-all") - .about("Reads a SLEEP file, iterates through all entries, prints raw bytes") + .about("Reads a single SLEEP file, iterates through all entries, prints raw bytes") .arg_from_usage("<FILE> 'SLEEP file to read'")) .get_matches(); match matches.subcommand() { ("info", Some(subm)) => { + let dir = Path::new(subm.value_of("DIR").unwrap()); + let prefix = subm.value_of("prefix").unwrap(); + let mut sdr = SleepDirRegister::open(dir, prefix, false)?; + //debug!(println!("{:?}", sdr)); + println!("Entry count: {}", sdr.len()?); + println!("Total size (bytes): {}", sdr.len_bytes()?); + }, + ("create", Some(subm)) => { + let dir = Path::new(subm.value_of("DIR").unwrap()); + let prefix = subm.value_of("prefix").unwrap(); + SleepDirRegister::create(dir, prefix)?; + println!("Done!"); + }, + ("file-info", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let sf = SleepFile::open(path, false)?; //debug!(println!("{:?}", sf)); @@ -42,7 +64,7 @@ fn run() -> Result<()> { println!("Entry Size (bytes): {}", sf.get_entry_size()); println!("Entry count: {}", sf.len()?); }, - ("create", Some(subm)) => { + ("file-create", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let algo_name = subm.value_of("algo_name").unwrap(); let algo_name = if algo_name.len() == 0 { @@ -57,7 +79,7 @@ fn run() -> Result<()> { algo_name)?; println!("Done!"); }, - ("read-all", Some(subm)) => { + ("file-read-all", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let mut sf = SleepFile::open(path, false)?; for i in 0..sf.len()? { |