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)]), + } + }) +} +