diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-10-31 23:56:21 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-11-01 18:01:00 +0100 |
commit | ec9710f1e79605744bf6015c097b03cddacc748e (patch) | |
tree | b3dc646cc1c9d010ca87f841f468cc769990cca1 /imag-link/src/main.rs | |
parent | b90dabaa97c5ce41afda976f0052880203f7e4e5 (diff) |
Rewrite external linking handler function to use less unwrap()
Diffstat (limited to 'imag-link/src/main.rs')
-rw-r--r-- | imag-link/src/main.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index bfaa239d..6f686683 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -213,16 +213,14 @@ fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockE fn handle_external_linking(rt: &Runtime) { let scmd = rt.cli().subcommand_matches("external").unwrap(); let entry_name = scmd.value_of("id").unwrap(); // enforced by clap - let entry = get_entry_by_name(rt, entry_name); - if entry.is_err() { - trace_error_exit(&entry.unwrap_err(), 1); - } - let entry = entry.unwrap(); - if entry.is_none() { - warn!("Entry not found: {:?}", entry_name); - return; - } - let mut entry = entry.unwrap(); + let mut entry = match get_entry_by_name(rt, entry_name) { + Err(e) => trace_error_exit(&e, 1), + Ok(None) => { + warn!("Entry not found: {:?}", entry_name); + return; + }, + Ok(Some(entry)) => entry + }; if scmd.is_present("add") { debug!("Adding link to entry!"); |