diff options
Diffstat (limited to 'src/bin/geniza-drive.rs')
-rw-r--r-- | src/bin/geniza-drive.rs | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/bin/geniza-drive.rs b/src/bin/geniza-drive.rs index 79ba480..62bfc90 100644 --- a/src/bin/geniza-drive.rs +++ b/src/bin/geniza-drive.rs @@ -7,7 +7,6 @@ extern crate env_logger; extern crate error_chain; extern crate geniza; -// TODO: more careful import use geniza::*; use std::path::Path; use clap::{App, Arg, SubCommand}; @@ -17,13 +16,12 @@ fn run() -> Result<()> { let matches = App::new("geniza-drive") .version(env!("CARGO_PKG_VERSION")) - // TODO: dat-dir for all commands up here, and have a default vaule ('./dat') .arg(Arg::with_name("dat-dir") .short("d") .long("dat-dir") .value_name("PATH") .help("dat drive directory") - .default_value(".dat") // TODO: needs to be default_value_os? + .default_value(".dat") .takes_value(true)) .subcommand( SubCommand::with_name("init") @@ -62,6 +60,22 @@ fn run() -> Result<()> { SubCommand::with_name("dump-entries") .about("Dump all entries in a debug-friendly format") ) + .subcommand( + SubCommand::with_name("copy") + .about("Internally copies a file in a dat archive") + .arg_from_usage("<FROM> 'path to copy from'") + .arg_from_usage("<TO> 'path to copy from'") + ) + .subcommand( + SubCommand::with_name("remove") + .about("Deletes a file path from dat archive") + .arg_from_usage("<FILE> 'file to delete'") + ) + .subcommand( + SubCommand::with_name("remove-dir-all") + .about("Recursively deletes a directory from the dat archive") + .arg_from_usage("<PATH> 'directory to delete'") + ) .get_matches(); let dir = Path::new(matches.value_of("dat-dir").unwrap()); @@ -78,6 +92,14 @@ fn run() -> Result<()> { println!("{}", entry.path.display()); } } + ("cat", Some(subm)) => { + let path = Path::new(subm.value_of("FILE").unwrap()); + let mut drive = DatDrive::open(dir, true)?; + let data = drive.read_file_bytes(&path)?; + // TODO: just write to stdout + let s = String::from_utf8(data).unwrap(); + println!("{}", s); + } ("import-file", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let mut drive = DatDrive::open(dir, true)?; @@ -97,15 +119,6 @@ fn run() -> Result<()> { }; drive.export_file(&path, &fpath)?; } - ("cat", Some(subm)) => { - let path = Path::new(subm.value_of("FILE").unwrap()); - let mut drive = DatDrive::open(dir, true)?; - let data = drive.read_file_bytes(&path)?; - // TODO: just write to stdout - let s = String::from_utf8(data).unwrap(); - println!("{}", s); - - } ("log", Some(_subm)) => { let mut drive = DatDrive::open(dir, false)?; for entry in drive.history(0) { @@ -143,6 +156,22 @@ fn run() -> Result<()> { } } } + ("copy", Some(subm)) => { + let from_path= Path::new(subm.value_of("FROM").unwrap()); + let to_path= Path::new(subm.value_of("FROM").unwrap()); + let mut drive = DatDrive::open(dir, true)?; + drive.copy_file(&from_path, &to_path)?; + } + ("remove", Some(subm)) => { + let path = Path::new(subm.value_of("FILE").unwrap()); + let mut drive = DatDrive::open(dir, true)?; + drive.remove_file(&path)?; + } + ("remove-dir-all", Some(subm)) => { + let path = Path::new(subm.value_of("FILE").unwrap()); + let mut drive = DatDrive::open(dir, true)?; + drive.remove_dir_all(&path)?; + } _ => { println!("Missing or unimplemented command!"); println!("{}", matches.usage()); |