From ad76ba22f345a181e86b50d4f75da1c2295a9f53 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 30 Oct 2017 21:43:47 -0700 Subject: more geniza-sleep commands (for debugging) --- src/bin/geniza-sleep.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src') diff --git a/src/bin/geniza-sleep.rs b/src/bin/geniza-sleep.rs index dafa33c..2e504b0 100644 --- a/src/bin/geniza-sleep.rs +++ b/src/bin/geniza-sleep.rs @@ -30,6 +30,13 @@ fn run() -> Result<()> { .arg_from_usage(" 'directory containing files'") .arg_from_usage(" 'prefix for each data file'"), ) + .subcommand( + SubCommand::with_name("chunk") + .about("Dumps raw data for a single given chunk from a register (by index)") + .arg_from_usage(" 'directory containing files'") + .arg_from_usage(" 'prefix for each data file'") + .arg_from_usage(" 'index of the data chunk to dump'"), + ) .subcommand( SubCommand::with_name("file-info") .about("Reads a single SLEEP file and shows some basic metadata") @@ -48,6 +55,18 @@ fn run() -> Result<()> { .about("Reads a single SLEEP file, iterates through all entries, prints raw bytes") .arg_from_usage(" 'SLEEP file to read'"), ) + .subcommand( + SubCommand::with_name("file-chunk") + .about("Dumps raw data for a single given chunk from a SLEEP file (by index)") + .arg_from_usage(" 'SLEEP file to read'") + .arg_from_usage(" 'index of the data chunk to dump'"), + ) + .subcommand( + SubCommand::with_name("write-example-alphabet") + .about("Creates a content register in the given folder, with example data added") + .arg_from_usage(" 'directory containing files'") + .arg_from_usage(" 'prefix for each data file'") + ) .get_matches(); @@ -66,6 +85,14 @@ fn run() -> Result<()> { SleepDirRegister::create(dir, prefix)?; println!("Done!"); } + ("chunk", Some(subm)) => { + let dir = Path::new(subm.value_of("DIR").unwrap()); + let prefix = subm.value_of("prefix").unwrap(); + let index = value_t_or_exit!(subm, "index", u64); + let mut sdr = SleepDirRegister::open(dir, prefix, false)?; + //debug!(println!("{:?}", sdr)); + println!("{:?}", sdr.get_data_entry(index)?); + } ("file-info", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let sf = SleepFile::open(path, false)?; @@ -101,6 +128,25 @@ fn run() -> Result<()> { println!("{}: {:?}", i, sf.read(i)); } } + ("file-chunk", Some(subm)) => { + let path = Path::new(subm.value_of("FILE").unwrap()); + let index = value_t_or_exit!(subm, "index", u64); + let mut sf = SleepFile::open(path, false)?; + //debug!(println!("{:?}", sdr)); + println!("{:?}", sf.read(index)?); + } + ("write-example-alphabet", Some(subm)) => { + let dir = Path::new(subm.value_of("DIR").unwrap()); + let prefix = subm.value_of("prefix").unwrap(); + let mut sdr = SleepDirRegister::create(dir, prefix)?; + sdr.append(&[0x61; 1])?; // a + sdr.append(&[0x62; 1])?; // b + sdr.append(&[0x63; 1])?; // c + sdr.append(&[0x64; 1])?; // d + sdr.append(&[0x65; 1])?; // e + sdr.append(&[0x66; 1])?; // f + println!("Done!"); + } _ => { println!("Missing or unimplemented command!"); println!("{}", matches.usage()); -- cgit v1.2.3