Adapt for new API
This commit is contained in:
parent
80c460dac9
commit
95e861b5ca
1 changed files with 46 additions and 37 deletions
|
@ -51,9 +51,10 @@ use toml_query::read::TomlValueReadExt;
|
|||
use libimagrt::runtime::Runtime;
|
||||
use libimagrt::setup::generate_runtime_setup;
|
||||
use libimagbookmark::collection::BookmarkCollection;
|
||||
use libimagbookmark::collection::BookmarkCollectionStore;
|
||||
use libimagbookmark::error::BookmarkError as BE;
|
||||
use libimagbookmark::link::Link as BookmarkLink;
|
||||
use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
|
||||
use libimagutil::info_result::*;
|
||||
|
||||
mod ui;
|
||||
|
||||
|
@ -85,16 +86,18 @@ fn add(rt: &Runtime) {
|
|||
let scmd = rt.cli().subcommand_matches("add").unwrap();
|
||||
let coll = get_collection_name(rt, "add", "collection");
|
||||
|
||||
BookmarkCollection::get(rt.store(), &coll)
|
||||
.and_then(|mut collection| {
|
||||
let mut collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.ok_or(BE::from(format!("No BookmarkcollectionStore '{}' found", coll)))
|
||||
.map_err_trace_exit_unwrap(1);
|
||||
|
||||
for url in scmd.values_of("urls").unwrap() { // unwrap saved by clap
|
||||
let _ = collection.add_link(BookmarkLink::from(url))?;
|
||||
let _ = collection
|
||||
.add_link(rt.store(), BookmarkLink::from(url))
|
||||
.map_err_trace_exit_unwrap(1);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.map_err_trace()
|
||||
.map_info_str("Ready")
|
||||
.ok();
|
||||
|
||||
info!("Ready");
|
||||
}
|
||||
|
||||
fn collection(rt: &Runtime) {
|
||||
|
@ -102,7 +105,7 @@ fn collection(rt: &Runtime) {
|
|||
|
||||
if scmd.is_present("add") { // adding a new collection
|
||||
let name = scmd.value_of("add").unwrap();
|
||||
if let Ok(_) = BookmarkCollection::new(rt.store(), &name) {
|
||||
if let Ok(_) = BookmarkCollectionStore::new(rt.store(), &name) {
|
||||
info!("Created: {}", name);
|
||||
} else {
|
||||
warn!("Creating collection {} failed", name);
|
||||
|
@ -112,7 +115,7 @@ fn collection(rt: &Runtime) {
|
|||
|
||||
if scmd.is_present("remove") { // remove a collection
|
||||
let name = scmd.value_of("remove").unwrap();
|
||||
if let Ok(_) = BookmarkCollection::delete(rt.store(), &name) {
|
||||
if let Ok(_) = BookmarkCollectionStore::delete(rt.store(), &name) {
|
||||
info!("Deleted: {}", name);
|
||||
} else {
|
||||
warn!("Deleting collection {} failed", name);
|
||||
|
@ -124,9 +127,12 @@ fn collection(rt: &Runtime) {
|
|||
fn list(rt: &Runtime) {
|
||||
let coll = get_collection_name(rt, "list", "collection");
|
||||
|
||||
BookmarkCollection::get(rt.store(), &coll)
|
||||
.map(|collection| {
|
||||
match collection.links() {
|
||||
let collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.ok_or(BE::from(format!("No BookmarkcollectionStore '{}' found", coll)))
|
||||
.map_err_trace_exit_unwrap(1);
|
||||
|
||||
match collection.links(rt.store()) {
|
||||
Ok(links) => {
|
||||
debug!("Listing...");
|
||||
for (i, link) in links.enumerate() {
|
||||
|
@ -139,8 +145,7 @@ fn list(rt: &Runtime) {
|
|||
},
|
||||
Err(e) => trace_error_exit(&e, 1),
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
|
||||
info!("Ready");
|
||||
}
|
||||
|
||||
|
@ -148,13 +153,17 @@ fn remove(rt: &Runtime) {
|
|||
let scmd = rt.cli().subcommand_matches("remove").unwrap();
|
||||
let coll = get_collection_name(rt, "list", "collection");
|
||||
|
||||
BookmarkCollection::get(rt.store(), &coll)
|
||||
.map(|mut collection| {
|
||||
let mut collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.ok_or(BE::from(format!("No BookmarkcollectionStore '{}' found", coll)))
|
||||
.map_err_trace_exit_unwrap(1);
|
||||
|
||||
for url in scmd.values_of("urls").unwrap() { // enforced by clap
|
||||
collection.remove_link(BookmarkLink::from(url)).map_err(|e| trace_error(&e)).ok();
|
||||
collection
|
||||
.remove_link(rt.store(), BookmarkLink::from(url))
|
||||
.map_err_trace_exit_unwrap(1);
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
|
||||
info!("Ready");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue