From c45b5ba975f78b23c7feb07e3cfaa171620c2f96 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 26 Jun 2016 11:17:30 +0200 Subject: [PATCH 1/7] Initial import --- imag-ref/Cargo.toml | 6 ++++++ imag-ref/src/main.rs | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 imag-ref/Cargo.toml create mode 100644 imag-ref/src/main.rs diff --git a/imag-ref/Cargo.toml b/imag-ref/Cargo.toml new file mode 100644 index 00000000..ca65a1a8 --- /dev/null +++ b/imag-ref/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "imag-ref" +version = "0.1.0" +authors = ["Matthias Beyer "] + +[dependencies] diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/imag-ref/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From d5cb5be4abb69242e410b7c6a403d2e08055f69e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 26 Jun 2016 11:29:47 +0200 Subject: [PATCH 2/7] Add dependencies --- imag-ref/Cargo.toml | 20 ++++++++++++++++++++ imag-ref/src/main.rs | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/imag-ref/Cargo.toml b/imag-ref/Cargo.toml index ca65a1a8..87f1f01b 100644 --- a/imag-ref/Cargo.toml +++ b/imag-ref/Cargo.toml @@ -4,3 +4,23 @@ version = "0.1.0" authors = ["Matthias Beyer "] [dependencies] +semver = "0.2.1" +clap = "2.1.1" +log = "0.3" +version = "2.0.1" + +[dependencies.libimagstore] +path = "../libimagstore" + +[dependencies.libimagrt] +path = "../libimagrt" + +[dependencies.libimagref] +path = "../libimagref" + +[dependencies.libimagerror] +path = "../libimagerror" + +[dependencies.libimagentrylist] +path = "../libimagentrylist" + diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs index e7a11a96..b4e11dcd 100644 --- a/imag-ref/src/main.rs +++ b/imag-ref/src/main.rs @@ -1,3 +1,14 @@ +#[macro_use] extern crate log; +#[macro_use] extern crate version; +extern crate semver; +extern crate clap; + +extern crate libimagstore; +extern crate libimagrt; +extern crate libimagref; +extern crate libimagerror; +extern crate libimagentrylist; + fn main() { println!("Hello, world!"); } From 56759ecba85cf3f75d9ef901b07824224019686e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 26 Jun 2016 11:30:04 +0200 Subject: [PATCH 3/7] Add ui module --- imag-ref/src/main.rs | 3 ++ imag-ref/src/ui.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 imag-ref/src/ui.rs diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs index b4e11dcd..fd546fb3 100644 --- a/imag-ref/src/main.rs +++ b/imag-ref/src/main.rs @@ -9,6 +9,9 @@ extern crate libimagref; extern crate libimagerror; extern crate libimagentrylist; +mod ui; +use ui::build_ui; + fn main() { println!("Hello, world!"); } diff --git a/imag-ref/src/ui.rs b/imag-ref/src/ui.rs new file mode 100644 index 00000000..e884c90f --- /dev/null +++ b/imag-ref/src/ui.rs @@ -0,0 +1,71 @@ +use clap::{Arg, App, SubCommand}; + +pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { + app + .subcommand(SubCommand::with_name("add") + .about("Add a reference to a file outside of the store") + .version("0.1") + .arg(Arg::with_name("path") + .long("path") + .short("p") + .takes_value(true) + .required(true) + .help("The path of the file") + .value_name("PATH")) + .arg(Arg::with_name("track-content") + .long("content-hash") + .short("C") + .takes_value(false) + .required(false) + .help("Hash the content for the reference")) + .arg(Arg::with_name("track-permissions") + .long("permission-tracking") + .short("P") + .takes_value(false) + .required(false) + .help("Rememeber the permissions of the referenced file")) + ) + + .subcommand(SubCommand::with_name("remove") + .about("Remove a reference") + .version("0.1") + .arg(Arg::with_name("hash") + .long("hash") + .short("h") + .takes_value(true) + .required(true) + .help("Remove the reference with this hash") + .value_name("HASH")) + + .arg(Arg::with_name("yes") + .long("yes") + .short("y") + .help("Don't ask whether this really should be done")) + ) + + .subcommand(SubCommand::with_name("list") + .about("List references in the store") + .version("0.1") + + .arg(Arg::with_name("check-dead") + .long("check-dead") + .short("d") + .help("Check each reference whether it is dead")) + + .arg(Arg::with_name("check-changed") + .long("check-changed") + .short("c") + .help("Check whether a reference had changed (content or permissions)")) + + .arg(Arg::with_name("check-changed-content") + .long("check-changed-content") + .short("C") + .help("Check whether the content of the referenced file changed")) + + .arg(Arg::with_name("check-changed-permissions") + .long("check-changed-perms") + .short("P") + .help("Check whether the permissions of the referenced file changed")) + + ) +} From 6fc05a027b6fae59490798b7f54644fdb9553716 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 26 Jun 2016 11:31:46 +0200 Subject: [PATCH 4/7] Add main() --- imag-ref/src/main.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs index fd546fb3..f16d7dcc 100644 --- a/imag-ref/src/main.rs +++ b/imag-ref/src/main.rs @@ -13,5 +13,34 @@ mod ui; use ui::build_ui; fn main() { - println!("Hello, world!"); + let rt = generate_runtime_setup("imag-ref", + &version!()[..], + "Reference files outside of the store", + build_ui); + rt.cli() + .subcommand_name() + .map(|name| { + debug!("Call: {}", name); + match name { + "add" => add(&rt), + "remove" => remove(&rt), + "list" => list(&rt), + _ => { + debug!("Unknown command"); // More error handling + }, + }; + }); } + +fn add(rt: &Runtime) { + unimplemented!() +} + +fn remove(rt: &Runtime) { + unimplemented!() +} + +fn list(rt: &Runtime) { + unimplemented!() +} + From 3eb5e8283947782d9b0afa1a0873c289c5180d7a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 26 Jun 2016 11:39:27 +0200 Subject: [PATCH 5/7] Impl add() --- imag-ref/src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs index f16d7dcc..3a7694b3 100644 --- a/imag-ref/src/main.rs +++ b/imag-ref/src/main.rs @@ -33,7 +33,23 @@ fn main() { } fn add(rt: &Runtime) { - unimplemented!() + let cmd = rt.cli().subcommand_matches("add").unwrap(); + let path = cmd.value_of("path").map(PathBuf::from).unwrap(); // saved by clap + + let flags = RefFlags::default() + .with_content_hashing(cmd.is_present("track-content")) + .with_permission_tracking(cmd.is_present("track-permissions")); + + match Ref::create(rt.store(), path, flags) { + Ok(r) => { + debug!("Reference created: {:?}", r); + info!("Ok"); + }, + Err(e) => { + trace_error(&e); + warn!("Failed to create reference"); + }, + } } fn remove(rt: &Runtime) { From 8eeb8bb31096ba3b0f2e1755d01ffc92721f7941 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 28 Jun 2016 22:45:37 +0200 Subject: [PATCH 6/7] Add imports --- imag-ref/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs index 3a7694b3..1e52d97e 100644 --- a/imag-ref/src/main.rs +++ b/imag-ref/src/main.rs @@ -12,6 +12,14 @@ extern crate libimagentrylist; mod ui; use ui::build_ui; +use std::path::PathBuf; + +use libimagref::reference::Ref; +use libimagref::flags::RefFlags; +use libimagerror::trace::trace_error; +use libimagrt::setup::generate_runtime_setup; +use libimagrt::runtime::Runtime; + fn main() { let rt = generate_runtime_setup("imag-ref", &version!()[..], From 5bfdd5a8277671719ea4f8ed90f1536376372110 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 28 Jun 2016 23:10:49 +0200 Subject: [PATCH 7/7] Impl remove() --- imag-ref/Cargo.toml | 3 +++ imag-ref/src/main.rs | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/imag-ref/Cargo.toml b/imag-ref/Cargo.toml index 87f1f01b..949b7ec0 100644 --- a/imag-ref/Cargo.toml +++ b/imag-ref/Cargo.toml @@ -21,6 +21,9 @@ path = "../libimagref" [dependencies.libimagerror] path = "../libimagerror" +[dependencies.libimaginteraction] +path = "../libimaginteraction" + [dependencies.libimagentrylist] path = "../libimagentrylist" diff --git a/imag-ref/src/main.rs b/imag-ref/src/main.rs index 1e52d97e..7fce0e7f 100644 --- a/imag-ref/src/main.rs +++ b/imag-ref/src/main.rs @@ -8,6 +8,7 @@ extern crate libimagrt; extern crate libimagref; extern crate libimagerror; extern crate libimagentrylist; +extern crate libimaginteraction; mod ui; use ui::build_ui; @@ -61,7 +62,23 @@ fn add(rt: &Runtime) { } fn remove(rt: &Runtime) { - unimplemented!() + use libimagref::error::RefErrorKind; + use libimagerror::into::IntoError; + use libimaginteraction::ask::ask_bool; + + let cmd = rt.cli().subcommand_matches("remove").unwrap(); + let hash = cmd.value_of("hash").map(String::from).unwrap(); // saved by clap + let yes = cmd.is_present("yes"); + + if yes || ask_bool(&format!("Delete Ref with hash '{}'", hash)[..], None) { + match Ref::delete_by_hash(rt.store(), hash) { + Err(e) => trace_error(&e), + Ok(_) => info!("Ok"), + } + } else { + info!("Aborted"); + } + } fn list(rt: &Runtime) {