From 44abcb69620eb3621b30f8d3b1acdade18662165 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 5 Nov 2017 19:51:46 -0800 Subject: more geniza-drive features --- src/bin/geniza-drive.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/bin/geniza-drive.rs b/src/bin/geniza-drive.rs index 79ad517..7f945b0 100644 --- a/src/bin/geniza-drive.rs +++ b/src/bin/geniza-drive.rs @@ -25,10 +25,25 @@ fn run() -> Result<()> { .help("dat drive directory") .default_value(".dat") // TODO: needs to be default_value_os? .takes_value(true)) + .subcommand( + SubCommand::with_name("init") + .about("Creates a blank drive") + ) .subcommand( SubCommand::with_name("ls") .about("Lists current files in this dat") ) + .subcommand( + SubCommand::with_name("cat") + .about("Prints a file (as a string) to stdout") + .arg_from_usage(" 'file to add'") + ) + .subcommand( + SubCommand::with_name("import-file") + .about("Adds an indivudal file to the dat") + .arg_from_usage(" 'file to add'") + .arg_from_usage("--target 'path to import the file to (if not top level)'") + ) .subcommand( SubCommand::with_name("log") .about("History of additions/deletions from this dat") @@ -45,6 +60,11 @@ fn run() -> Result<()> { let dir = Path::new(matches.value_of("dat-dir").unwrap()); match matches.subcommand() { + ("init", Some(_subm)) => { + let drive = DatDrive::create(dir)?; + // TODO: print public key in hex + println!("Done!"); + } ("ls", Some(_subm)) => { let mut drive = DatDrive::open(dir, false)?; for entry in drive.read_dir_recursive("/") { @@ -52,6 +72,25 @@ fn run() -> Result<()> { println!("{}", entry.path.display()); } } + ("import-file", Some(subm)) => { + let path = Path::new(subm.value_of("FILE").unwrap()); + let mut drive = DatDrive::open(dir, true)?; + let fpath = match subm.value_of("target") { + None => Path::new("/").join(path.file_name().unwrap()), + Some(p) => Path::new("/").join(p) + }; + drive.import_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) { -- cgit v1.2.3