handle errors in editing files

This commit is contained in:
Dr. Matthias Ratajczak
2022-12-02 17:51:10 +01:00
parent 533bc71223
commit 6d01abc79e
4 changed files with 29 additions and 9 deletions
+11
View File
@@ -0,0 +1,11 @@
use std::env::var;
use anyhow::{anyhow, Result};
pub(crate) fn get_editor() -> Result<String> {
check_vars_in_order(&["EDITOR", "VISUAL"]).ok_or_else(|| anyhow!("could not find editor"))
}
fn check_vars_in_order(vars: &[&str]) -> Option<String> {
vars.iter().flat_map(|v| var(v).ok()).next()
}