diff options
Diffstat (limited to 'bin/domain/imag-bookmark/src/ui.rs')
-rw-r--r-- | bin/domain/imag-bookmark/src/ui.rs | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/bin/domain/imag-bookmark/src/ui.rs b/bin/domain/imag-bookmark/src/ui.rs index 93a48cdb..e248a420 100644 --- a/bin/domain/imag-bookmark/src/ui.rs +++ b/bin/domain/imag-bookmark/src/ui.rs @@ -17,23 +17,21 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use clap::{Arg, App, SubCommand}; +use std::path::PathBuf; + +use failure::Fallible as Result; +use clap::{Arg, ArgMatches, App, SubCommand}; use libimagutil::cli_validators::*; +use libimagstore::storeid::StoreId; +use libimagstore::storeid::IntoStoreId; +use libimagrt::runtime::IdPathProvider; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app .subcommand(SubCommand::with_name("add") .about("Add bookmarks") .version("0.1") - .arg(Arg::with_name("collection") - .long("collection") - .short("c") - .takes_value(true) - .required(false) - .multiple(false) - .value_name("COLLECTION") - .help("Add to this collection, if not specified default from config will be used")) .arg(Arg::with_name("urls") .index(1) .takes_value(true) @@ -47,22 +45,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .subcommand(SubCommand::with_name("remove") .about("Remove bookmarks") .version("0.1") - .arg(Arg::with_name("collection") - .long("collection") - .short("c") - .takes_value(true) - .required(false) - .multiple(false) - .value_name("COLLECTION") - .help("Remove from this collection, if not specified default from config will be used")) - .arg(Arg::with_name("urls") + .arg(Arg::with_name("ids") .index(1) .takes_value(true) .required(true) .multiple(true) - .value_name("URL") - .validator(is_url) - .help("Remove this url(s)")) + .value_name("ID") + .help("Remove these urls, specified as ID")) ) // .subcommand(SubCommand::with_name("open") @@ -79,32 +68,41 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { // ) .subcommand(SubCommand::with_name("list") - .about("List bookmarks") + .about("List bookmarks, if used in pipe, ignores everything that is not a bookmark") .version("0.1") - .arg(Arg::with_name("collection") - .long("collection") - .short("c") + + .arg(Arg::with_name("ids") + .index(1) .takes_value(true) .required(false) - .multiple(false) - .value_name("COLLECTION") - .help("Select from this collection, if not specified default from config will be used")) + .multiple(true) + .value_name("ID") + .help("IDs of bookmarks to list")) ) +} - .subcommand(SubCommand::with_name("collection") - .about("Collection commands") - .version("0.1") - .arg(Arg::with_name("add") - .long("add") - .short("a") - .takes_value(true) - .value_name("NAME") - .help("Add a collection with this name")) - .arg(Arg::with_name("remove") - .long("remove") - .short("r") - .takes_value(true) - .value_name("NAME") - .help("Remove a collection with this name (and all links)")) - ) +pub struct PathProvider; +impl IdPathProvider for PathProvider { + fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> { + fn no_ids_error() -> Result<Option<Vec<StoreId>>> { + Err(format_err!("Command does not get IDs as input")) + } + + fn get_id_paths(field: &str, subm: &ArgMatches) -> Result<Option<Vec<StoreId>>> { + subm.values_of(field) + .map(|v| v + .map(PathBuf::from) + .map(|pb| pb.into_storeid()) + .collect::<Result<Vec<_>>>() + ) + .transpose() + } + + match matches.subcommand() { + ("add", _) => no_ids_error(), + ("remove", Some(subm)) => get_id_paths("ids", subm), + ("list", Some(subm)) => get_id_paths("ids", subm), + (other, _) => Err(format_err!("Not a known command: {}", other)), + } + } } |