diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-04-12 21:12:38 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-04-14 17:18:02 +0200 |
commit | 9116409c1643121a4b7e1986ea28738323115fae (patch) | |
tree | 13d3855033f1b8fe2e2ab5700635ada0ce4bc5c9 /imag-link | |
parent | 3719bf8ae9786e0abe06cfb7d24a3ca1ed2435ea (diff) |
Implement the --list argument
Diffstat (limited to 'imag-link')
-rw-r--r-- | imag-link/src/main.rs | 99 |
1 files changed, 63 insertions, 36 deletions
diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index aaa15470..1d2b3a36 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -62,47 +62,74 @@ fn handle_internal_linking(rt: &Runtime) { use libimaglink::internal::InternalLinker; use libimagutil::trace::trace_error; - let mut from = { - let mut from = get_from_entry(&rt); - if from.is_none() { - warn!("No 'from' entry"); - exit(1); - } - from.unwrap() - }; - debug!("Link from = {:?}", from.deref()); - - let mut to = { - let mut to = get_to_entries(&rt); - if to.is_none() { - warn!("No 'to' entry"); - exit(1); - } - to.unwrap() - }; - debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>()); + 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; + } + }); + }, - match rt.cli().subcommand_matches("internal").unwrap().subcommand_name() { - Some("add") => { - for mut to_entry in to { - if let Err(e) = to_entry.add_internal_link(&mut from) { + Err(e) => { trace_error(&e); - exit(1); - } + break; + }, } - }, - - Some("remove") => { - for mut to_entry in to { - if let Err(e) = to_entry.remove_internal_link(&mut from) { - trace_error(&e); - exit(1); - } + } + debug!("Listing ready!"); + } else { + let mut from = { + let mut from = get_from_entry(&rt); + if from.is_none() { + warn!("No 'from' entry"); + exit(1); + } + from.unwrap() + }; + debug!("Link from = {:?}", from.deref()); + + let mut to = { + let mut to = get_to_entries(&rt); + if to.is_none() { + warn!("No 'to' entry"); + exit(1); } - }, + to.unwrap() + }; + debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>()); + + match cmd.subcommand_name() { + Some("add") => { + for mut to_entry in to { + if let Err(e) = to_entry.add_internal_link(&mut from) { + trace_error(&e); + exit(1); + } + } + }, + + Some("remove") => { + for mut to_entry in to { + if let Err(e) = to_entry.remove_internal_link(&mut from) { + trace_error(&e); + exit(1); + } + } + }, - _ => unreachable!(), - // as the get_from_entry()/get_to_entries() would have errored + _ => unreachable!(), + }; } } |