From 9f3878d43f56c10a4db75bd2fb6ef151ab1fc20a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 26 May 2016 08:49:05 +0200 Subject: [PATCH 1/4] Initial import --- libimagentryselect/Cargo.toml | 6 ++++++ libimagentryselect/src/lib.rs | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 libimagentryselect/Cargo.toml create mode 100644 libimagentryselect/src/lib.rs diff --git a/libimagentryselect/Cargo.toml b/libimagentryselect/Cargo.toml new file mode 100644 index 00000000..753f3c86 --- /dev/null +++ b/libimagentryselect/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "libimagentryselect" +version = "0.1.0" +authors = ["Matthias Beyer "] + +[dependencies] diff --git a/libimagentryselect/src/lib.rs b/libimagentryselect/src/lib.rs new file mode 100644 index 00000000..cdfbe1aa --- /dev/null +++ b/libimagentryselect/src/lib.rs @@ -0,0 +1,6 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + } +} From a0b7e9b9801c6c253cbf125e5cb5fe73ff338009 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 26 May 2016 10:35:11 +0200 Subject: [PATCH 2/4] Add dependencies --- libimagentryselect/Cargo.toml | 10 ++++++++++ libimagentryselect/src/lib.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libimagentryselect/Cargo.toml b/libimagentryselect/Cargo.toml index 753f3c86..ccd52838 100644 --- a/libimagentryselect/Cargo.toml +++ b/libimagentryselect/Cargo.toml @@ -4,3 +4,13 @@ version = "0.1.0" authors = ["Matthias Beyer "] [dependencies] +clap = "2" +log = "0.3" +interactor = "0.1" + +[dependencies.libimagstore] +path = "../libimagstore" + +[dependencies.libimagerror] +path = "../libimagerror" + diff --git a/libimagentryselect/src/lib.rs b/libimagentryselect/src/lib.rs index cdfbe1aa..c7472aa6 100644 --- a/libimagentryselect/src/lib.rs +++ b/libimagentryselect/src/lib.rs @@ -1,6 +1,6 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - } -} +extern crate clap; +extern crate log; +extern crate interactor; + +extern crate libimagstore; + From bad8e1ced17362cb759c9c1b4c55742a133e6ec7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 26 May 2016 10:35:26 +0200 Subject: [PATCH 3/4] Add id argument helper and getter --- libimagentryselect/src/lib.rs | 2 ++ libimagentryselect/src/ui.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 libimagentryselect/src/ui.rs diff --git a/libimagentryselect/src/lib.rs b/libimagentryselect/src/lib.rs index c7472aa6..98806550 100644 --- a/libimagentryselect/src/lib.rs +++ b/libimagentryselect/src/lib.rs @@ -4,3 +4,5 @@ extern crate interactor; extern crate libimagstore; +pub mod ui; + diff --git a/libimagentryselect/src/ui.rs b/libimagentryselect/src/ui.rs new file mode 100644 index 00000000..9be677ac --- /dev/null +++ b/libimagentryselect/src/ui.rs @@ -0,0 +1,35 @@ +use clap::{Arg, ArgMatches}; + +use libimagstore::storeid::StoreId; + +pub fn id_argument<'a, 'b>() -> Arg<'a, 'b> { + Arg::with_name(id_argument_name()) + .short(id_argument_short()) + .long(id_argument_long()) + .takes_value(true) + .multiple(true) + .help("Specify the Store-Id") +} + +pub fn id_argument_name() -> &'static str { + "id-argument" +} + +pub fn id_argument_short() -> &'static str { + "i" +} + +pub fn id_argument_long() -> &'static str { + "id" +} + +pub fn get_id(matches: &ArgMatches) -> Option> { + matches.values_of(id_argument_name()) + .map(|vals| { + vals.into_iter() + .map(String::from) + .map(StoreId::from) + .collect() + }) +} + From 2aeb853c5f0465182d740a4702c20ce28450f5c0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 26 May 2016 10:41:25 +0200 Subject: [PATCH 4/4] Implement get_or_select_id() --- libimagentryselect/src/lib.rs | 1 + libimagentryselect/src/ui.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libimagentryselect/src/lib.rs b/libimagentryselect/src/lib.rs index 98806550..182aecdb 100644 --- a/libimagentryselect/src/lib.rs +++ b/libimagentryselect/src/lib.rs @@ -3,6 +3,7 @@ extern crate log; extern crate interactor; extern crate libimagstore; +extern crate libimagerror; pub mod ui; diff --git a/libimagentryselect/src/ui.rs b/libimagentryselect/src/ui.rs index 9be677ac..c8c524d5 100644 --- a/libimagentryselect/src/ui.rs +++ b/libimagentryselect/src/ui.rs @@ -1,6 +1,9 @@ +use std::path::PathBuf; + use clap::{Arg, ArgMatches}; use libimagstore::storeid::StoreId; +use libimagerror::trace::trace_error; pub fn id_argument<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name(id_argument_name()) @@ -33,3 +36,18 @@ pub fn get_id(matches: &ArgMatches) -> Option> { }) } +pub fn get_or_select_id(matches: &ArgMatches, store_path: &PathBuf) -> Option> { + use interactor::{pick_file, default_menu_cmd}; + + get_id(matches).or_else(|| { + match pick_file(default_menu_cmd, store_path.clone()) { + Err(e) => { + trace_error(&e); + None + }, + + Ok(p) => Some(vec![StoreId::from(p)]), + } + }) +} +