Merge pull request #829 from matthiasbeyer/imag-link/reduce-unwraps
Imag link/reduce unwraps
This commit is contained in:
commit
13c57aa0ce
1 changed files with 74 additions and 79 deletions
|
@ -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>>());
|
||||
|
||||
|
@ -163,6 +159,7 @@ fn handle_internal_linking(rt: &Runtime) {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_from_entry<'a>(rt: &'a Runtime) -> Option<FileLockEntry<'a>> {
|
||||
|
@ -216,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() {
|
||||
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;
|
||||
}
|
||||
let mut entry = entry.unwrap();
|
||||
},
|
||||
Ok(Some(entry)) => entry
|
||||
};
|
||||
|
||||
if scmd.is_present("add") {
|
||||
debug!("Adding link to entry!");
|
||||
|
|
Loading…
Reference in a new issue