Extract internal linking list call handling
This commit is contained in:
parent
0e1ea242ca
commit
14735aa4c4
1 changed files with 48 additions and 44 deletions
|
@ -55,6 +55,7 @@ use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
|
use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
|
||||||
use libimagentrylink::external::ExternalLinker;
|
use libimagentrylink::external::ExternalLinker;
|
||||||
|
use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagutil::warn_result::*;
|
use libimagutil::warn_result::*;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagutil::info_result::*;
|
use libimagutil::info_result::*;
|
||||||
|
@ -83,55 +84,12 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_internal_linking(rt: &Runtime) {
|
fn handle_internal_linking(rt: &Runtime) {
|
||||||
use libimagentrylink::internal::InternalLinker;
|
|
||||||
use libimagentrylink::external::is_external_link_storeid;
|
|
||||||
|
|
||||||
debug!("Handle internal linking call");
|
debug!("Handle internal linking call");
|
||||||
let cmd = rt.cli().subcommand_matches("internal").unwrap();
|
let cmd = rt.cli().subcommand_matches("internal").unwrap();
|
||||||
|
|
||||||
match cmd.value_of("list") {
|
match cmd.value_of("list") {
|
||||||
Some(list) => {
|
Some(list) => handle_internal_linking_list_call(rt, cmd, list),
|
||||||
debug!("List...");
|
|
||||||
for entry in list.split(',') {
|
|
||||||
debug!("Listing for '{}'", entry);
|
|
||||||
match get_entry_by_name(rt, entry) {
|
|
||||||
Ok(Some(e)) => {
|
|
||||||
e.get_internal_links()
|
|
||||||
.map(|iter| {
|
|
||||||
iter.filter(move |id| {
|
|
||||||
cmd.is_present("list-externals-too") || !is_external_link_storeid(&id)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.map(|links| {
|
|
||||||
let i = links
|
|
||||||
.filter_map(|l| {
|
|
||||||
l.to_str()
|
|
||||||
.map_warn_err(|e| format!("Failed to convert StoreId to string: {:?}", e))
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.enumerate();
|
|
||||||
|
|
||||||
for (i, link) in i {
|
|
||||||
println!("{: <3}: {}", i, link);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map_err_trace()
|
|
||||||
.ok();
|
|
||||||
},
|
|
||||||
|
|
||||||
Ok(None) => {
|
|
||||||
warn!("Entry not found: {:?}", entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(e) => {
|
|
||||||
trace_error(&e);
|
|
||||||
break;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug!("Listing ready!");
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
match cmd.subcommand_name() {
|
match cmd.subcommand_name() {
|
||||||
Some("add") => {
|
Some("add") => {
|
||||||
|
@ -158,6 +116,52 @@ fn handle_internal_linking(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn handle_internal_linking_list_call(rt: &Runtime, cmd: &ArgMatches, list: &str) {
|
||||||
|
use libimagentrylink::external::is_external_link_storeid;
|
||||||
|
|
||||||
|
debug!("List...");
|
||||||
|
for entry in list.split(',') {
|
||||||
|
debug!("Listing for '{}'", entry);
|
||||||
|
match get_entry_by_name(rt, entry) {
|
||||||
|
Ok(Some(e)) => {
|
||||||
|
e.get_internal_links()
|
||||||
|
.map(|iter| {
|
||||||
|
iter.filter(move |id| {
|
||||||
|
cmd.is_present("list-externals-too") || !is_external_link_storeid(&id)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|links| {
|
||||||
|
let i = links
|
||||||
|
.filter_map(|l| {
|
||||||
|
l.to_str()
|
||||||
|
.map_warn_err(|e| format!("Failed to convert StoreId to string: {:?}", e))
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
.enumerate();
|
||||||
|
|
||||||
|
for (i, link) in i {
|
||||||
|
println!("{: <3}: {}", i, link);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map_err_trace()
|
||||||
|
.ok();
|
||||||
|
},
|
||||||
|
|
||||||
|
Ok(None) => {
|
||||||
|
warn!("Entry not found: {:?}", entry);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(e) => {
|
||||||
|
trace_error(&e);
|
||||||
|
break;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug!("Listing ready!");
|
||||||
|
}
|
||||||
|
|
||||||
fn get_from_to_entry<'a>(rt: &'a Runtime, subcommand: &str) -> (FileLockEntry<'a>, Vec<FileLockEntry<'a>>) {
|
fn get_from_to_entry<'a>(rt: &'a Runtime, subcommand: &str) -> (FileLockEntry<'a>, Vec<FileLockEntry<'a>>) {
|
||||||
let from = match get_from_entry(&rt, subcommand) {
|
let from = match get_from_entry(&rt, subcommand) {
|
||||||
None => warn_exit("No 'from' entry", 1),
|
None => warn_exit("No 'from' entry", 1),
|
||||||
|
|
Loading…
Reference in a new issue