Implement the --list argument

This commit is contained in:
Matthias Beyer 2016-04-12 21:12:38 +02:00
parent 3719bf8ae9
commit 9116409c16

View file

@ -62,47 +62,74 @@ fn handle_internal_linking(rt: &Runtime) {
use libimaglink::internal::InternalLinker; use libimaglink::internal::InternalLinker;
use libimagutil::trace::trace_error; use libimagutil::trace::trace_error;
let mut from = { debug!("Handle internal linking call");
let mut from = get_from_entry(&rt); let cmd = rt.cli().subcommand_matches("internal").unwrap();
if from.is_none() {
warn!("No 'from' entry");
exit(1);
}
from.unwrap()
};
debug!("Link from = {:?}", from.deref());
let mut to = { if cmd.is_present("list") {
let mut to = get_to_entries(&rt); debug!("List...");
if to.is_none() { for entry in cmd.value_of("list").unwrap().split(",") {
warn!("No 'to' entry"); debug!("Listing for '{}'", entry);
exit(1); match get_entry_by_name(rt, entry) {
} Ok(e) => {
to.unwrap() e.get_internal_links()
}; .map(|links| {
debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>()); 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() { Err(e) => {
Some("add") => {
for mut to_entry in to {
if let Err(e) = to_entry.add_internal_link(&mut from) {
trace_error(&e); trace_error(&e);
exit(1); break;
} },
} }
}, }
debug!("Listing ready!");
Some("remove") => { } else {
for mut to_entry in to { let mut from = {
if let Err(e) = to_entry.remove_internal_link(&mut from) { let mut from = get_from_entry(&rt);
trace_error(&e); if from.is_none() {
exit(1); warn!("No 'from' entry");
} exit(1);
} }
}, from.unwrap()
};
debug!("Link from = {:?}", from.deref());
_ => unreachable!(), let mut to = {
// as the get_from_entry()/get_to_entries() would have errored 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!(),
};
} }
} }