aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-11-05 19:51:46 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-11-05 19:51:46 -0800
commit44abcb69620eb3621b30f8d3b1acdade18662165 (patch)
tree9e7735b1213c31ead901acc86cd06205eba7a782 /src
parentfcdc7a6d413f5e5ba213f6d421e8e117696bf0d0 (diff)
downloadgeniza-44abcb69620eb3621b30f8d3b1acdade18662165.tar.gz
geniza-44abcb69620eb3621b30f8d3b1acdade18662165.zip
more geniza-drive features
Diffstat (limited to 'src')
-rw-r--r--src/bin/geniza-drive.rs39
1 files changed, 39 insertions, 0 deletions
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
@@ -26,10 +26,25 @@ fn run() -> Result<()> {
.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> 'file to add'")
+ )
+ .subcommand(
+ SubCommand::with_name("import-file")
+ .about("Adds an indivudal file to the dat")
+ .arg_from_usage("<FILE> 'file to add'")
+ .arg_from_usage("--target <path> '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) {