Rewrite external linking handler function to use less unwrap()

This commit is contained in:
Matthias Beyer 2016-10-31 23:56:21 +01:00
parent b90dabaa97
commit ec9710f1e7

View file

@ -213,16 +213,14 @@ fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockE
fn handle_external_linking(rt: &Runtime) { fn handle_external_linking(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("external").unwrap(); let scmd = rt.cli().subcommand_matches("external").unwrap();
let entry_name = scmd.value_of("id").unwrap(); // enforced by clap let entry_name = scmd.value_of("id").unwrap(); // enforced by clap
let entry = get_entry_by_name(rt, entry_name); let mut entry = match get_entry_by_name(rt, entry_name) {
if entry.is_err() { Err(e) => trace_error_exit(&e, 1),
trace_error_exit(&entry.unwrap_err(), 1); Ok(None) => {
}
let entry = entry.unwrap();
if entry.is_none() {
warn!("Entry not found: {:?}", entry_name); warn!("Entry not found: {:?}", entry_name);
return; return;
} },
let mut entry = entry.unwrap(); Ok(Some(entry)) => entry
};
if scmd.is_present("add") { if scmd.is_present("add") {
debug!("Adding link to entry!"); debug!("Adding link to entry!");