Merge pull request #337 from matthiasbeyer/imag-link/list-implementation

Imag link/list implementation
This commit is contained in:
Matthias Beyer 2016-04-16 13:29:13 +02:00
commit 17610efd74
2 changed files with 68 additions and 41 deletions

View file

@ -62,6 +62,33 @@ fn handle_internal_linking(rt: &Runtime) {
use libimaglink::internal::InternalLinker; use libimaglink::internal::InternalLinker;
use libimagutil::trace::trace_error; use libimagutil::trace::trace_error;
debug!("Handle internal linking call");
let cmd = rt.cli().subcommand_matches("internal").unwrap();
if cmd.is_present("list") {
debug!("List...");
for entry in cmd.value_of("list").unwrap().split(",") {
debug!("Listing for '{}'", entry);
match get_entry_by_name(rt, entry) {
Ok(e) => {
e.get_internal_links()
.map(|links| {
let mut i = 0;
for link in links.iter().map(|l| l.to_str()).filter_map(|x| x) {
println!("{: <3}: {}", i, link);
i += 1;
}
});
},
Err(e) => {
trace_error(&e);
break;
},
}
}
debug!("Listing ready!");
} else {
let mut from = { let mut from = {
let mut from = get_from_entry(&rt); let mut from = get_from_entry(&rt);
if from.is_none() { if from.is_none() {
@ -82,7 +109,7 @@ fn handle_internal_linking(rt: &Runtime) {
}; };
debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>()); debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>());
match rt.cli().subcommand_matches("internal").unwrap().subcommand_name() { match cmd.subcommand_name() {
Some("add") => { Some("add") => {
for mut to_entry in to { for mut to_entry in to {
if let Err(e) = to_entry.add_internal_link(&mut from) { if let Err(e) = to_entry.add_internal_link(&mut from) {
@ -102,7 +129,7 @@ fn handle_internal_linking(rt: &Runtime) {
}, },
_ => unreachable!(), _ => unreachable!(),
// as the get_from_entry()/get_to_entries() would have errored };
} }
} }

View file

@ -44,7 +44,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.arg(Arg::with_name("list") .arg(Arg::with_name("list")
.long("list") .long("list")
.short("l") .short("l")
.takes_value(false) .takes_value(true)
.required(false) .required(false)
.help("List links to this entry")) .help("List links to this entry"))
) )