Rewrite internal linking handling to use less unwrap()

This commit is contained in:
Matthias Beyer 2016-10-31 23:55:17 +01:00
parent fa64c2d27d
commit b90dabaa97

View file

@ -88,9 +88,10 @@ fn handle_internal_linking(rt: &Runtime) {
debug!("Handle internal linking call");
let cmd = rt.cli().subcommand_matches("internal").unwrap();
if cmd.is_present("list") {
match cmd.value_of("list") {
Some(list) => {
debug!("List...");
for entry in cmd.value_of("list").unwrap().split(',') {
for entry in list.split(',') {
debug!("Listing for '{}'", entry);
match get_entry_by_name(rt, entry) {
Ok(Some(e)) => {
@ -124,22 +125,17 @@ fn handle_internal_linking(rt: &Runtime) {
}
}
debug!("Listing ready!");
} else {
let mut from = {
let from = get_from_entry(&rt);
if from.is_none() {
warn_exit("No 'from' entry", 1);
}
from.unwrap()
},
None => {
let mut from = match get_from_entry(&rt) {
None => warn_exit("No 'from' entry", 1),
Some(s) => s,
};
debug!("Link from = {:?}", from.deref());
let to = {
let to = get_to_entries(&rt);
if to.is_none() {
warn_exit("No 'to' entry", 1);
}
to.unwrap()
let to = match get_to_entries(&rt) {
None => warn_exit("No 'to' entry", 1),
Some(to) => to,
};
debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>());
@ -164,6 +160,7 @@ fn handle_internal_linking(rt: &Runtime) {
};
}
}
}
fn get_from_entry<'a>(rt: &'a Runtime) -> Option<FileLockEntry<'a>> {
rt.cli()