Implement get_or_select_id()

This commit is contained in:
Matthias Beyer 2016-05-26 10:41:25 +02:00
parent bad8e1ced1
commit 2aeb853c5f
2 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@ extern crate log;
extern crate interactor;
extern crate libimagstore;
extern crate libimagerror;
pub mod ui;

View File

@ -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<Vec<StoreId>> {
})
}
pub fn get_or_select_id(matches: &ArgMatches, store_path: &PathBuf) -> Option<Vec<StoreId>> {
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)]),
}
})
}