aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/geniza-register.rs68
-rw-r--r--src/bin/geniza-sleep.rs4
2 files changed, 70 insertions, 2 deletions
diff --git a/src/bin/geniza-register.rs b/src/bin/geniza-register.rs
new file mode 100644
index 0000000..6962be1
--- /dev/null
+++ b/src/bin/geniza-register.rs
@@ -0,0 +1,68 @@
+
+#[macro_use]
+extern crate clap;
+
+extern crate geniza;
+
+// TODO: more careful import
+use geniza::*;
+use std::path::Path;
+
+use clap::{App, SubCommand};
+
+fn run() -> Result<()> {
+
+ 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 sdr = SleepDirRegister::open(dir, prefix, false)?;
+ //debug!(println!("{:?}", sdr));
+ println!("Entry count: {}", sdr.len()?);
+ },
+ ("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(())
+}
+
+// TODO: is there a shorter error_chain 'main()' to use here?
+fn main() {
+ if let Err(ref e) = run() {
+ println!("error: {}", e);
+
+ for e in e.iter().skip(1) {
+ println!("caused by: {}", e);
+ }
+
+ // The backtrace is not always generated. Try to run this example
+ // with `RUST_BACKTRACE=1`.
+ if let Some(backtrace) = e.backtrace() {
+ println!("backtrace: {:?}", backtrace);
+ }
+
+ ::std::process::exit(1);
+ }
+}
diff --git a/src/bin/geniza-sleep.rs b/src/bin/geniza-sleep.rs
index b7bb88e..5061dc9 100644
--- a/src/bin/geniza-sleep.rs
+++ b/src/bin/geniza-sleep.rs
@@ -37,7 +37,7 @@ fn run() -> Result<()> {
println!("Magic: 0x{:X}", sf.get_magic());
println!("Algorithm: '{}'", sf.get_algorithm().or(Some("".to_string())).unwrap());
println!("Entry Size (bytes): {}", sf.get_entry_size());
- println!("Entry count: {}", sf.length()?);
+ println!("Entry count: {}", sf.len()?);
},
("create", Some(subm)) => {
let path = Path::new(subm.value_of("FILE").unwrap());
@@ -57,7 +57,7 @@ fn run() -> Result<()> {
("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.length()? {
+ for i in 0..sf.len()? {
println!("{}: {:?}", i, sf.read(i));
}
},