Tabbing now works, impelemented preliminary error message handling

This commit is contained in:
Oliver Atkinson
2025-04-08 12:13:19 -06:00
parent 727b2f0b51
commit acb49d7a4d
2 changed files with 66 additions and 113 deletions

View File

@@ -102,7 +102,7 @@ pub fn search_for_word(word: &str, from_files: &Bible) -> Vec<String> {
found
}
pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String> {
pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Result<String, String> {
// expecting query to be in format:
// Gen 1:2
// Gen 1:2-5
@@ -135,11 +135,11 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
for (_, i) in &res {
eprintln!("\t{i}");
}
return None;
return Err(format!("Ambigious input '{book}'"));
}
_ => {
eprintln!("'{book}' is not a book");
return None;
return Err(format!("'{book}' is not a book"));
}
};
@@ -162,10 +162,10 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
.map(|(bible,book,chapter)| (*bible,*book,chapter.unwrap()))
.collect::<Vec<(&Bible, &Book, &Chapter)>>()
} else {
return None;
return Err(format!("Chapter number could not be parsed from {chapter}"));
}
} else {
return None;
return Err(format!("A chapter was not passed"));
};
// Get the verse in each Bible
@@ -190,9 +190,9 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
}
}
}
return Some(buf);
return Ok(buf);
}
return None;
return Err(format!("Could not parse '{sn}' or '{en}' into numbers"));
}
// only one verse
(Some(ver_num), None) => {
@@ -206,13 +206,13 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
);
}
}
return Some(buf);
return Ok(buf);
}
return None;
return Err(format!("Could not parse '{ver_num}' into a number"));
}
_ => {
// couldn't parse verse
return None;
return Err(format!("Couldn't parse '{:?}' or '{:?}' into verse numbers", start, end));
}
}
}
@@ -226,7 +226,7 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
);
buf += &format!("{}", chapter);
}
return Some(buf);
return Ok(buf);
}
}
}