diff options
author | syn <isaqtm@gmail.com> | 2020-02-18 00:54:44 +0300 |
---|---|---|
committer | syn <isaqtm@gmail.com> | 2020-02-18 00:54:44 +0300 |
commit | 0c2e1910bd05ac7c783f0c815ca44539d9ff557e (patch) | |
tree | caee715880efc63bdd3e67de801c6516b671f9a4 /src | |
parent | 37b0c9e8f41049c6cea9122c7746ac6426983007 (diff) | |
download | evr-0c2e1910bd05ac7c783f0c815ca44539d9ff557e.tar.gz |
Abort if no config found
Diffstat (limited to 'src')
-rw-r--r-- | src/conf.rs | 19 | ||||
-rw-r--r-- | src/main.rs | 9 |
2 files changed, 10 insertions, 18 deletions
diff --git a/src/conf.rs b/src/conf.rs index 8aeb8e3..26a4832 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,7 +1,6 @@ use serde_derive::Deserialize; use std::path::{ PathBuf, Path }; use toml::de; -use log::{ error }; type Error = std::io::Error; use std::io::ErrorKind; @@ -9,7 +8,7 @@ use std::io::ErrorKind; use crate::backends::{ Backend, PythonBackend, ClangBackend }; -#[derive(Debug, Deserialize, Default)] +#[derive(Debug, Deserialize)] pub struct Conf { #[serde(skip)] path: Option<PathBuf>, @@ -43,21 +42,7 @@ impl Conf { } -pub fn get_conf() -> Conf { - match get_conf_maybe() { - Ok(c) => c, - Err(e) => { - match e.kind() { - ErrorKind::InvalidData => error!("parse: {}", e), - _ => error!("{}", e) - }; - Default::default() - } - } -} - - -pub fn get_conf_maybe() -> Result<Conf, Error> { +pub fn get_conf() -> Result<Conf, Error> { let mut current = std::env::current_dir()?; let path = loop { let candidate = current.join(".evr"); diff --git a/src/main.rs b/src/main.rs index e4c79ec..b25443d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,14 @@ fn main() { let src_path: std::path::PathBuf = matches.value_of("src") .expect("src is required") .into(); - let config = conf::get_conf(); + + let config = match conf::get_conf() { + Ok(c) => c, + Err(err) => { + error!("could not load config: {}", err); + std::process::exit(64); // EX_USAGE (BSD sysexits(3)) + } + }; if src_path.exists() { if let Some(backend) = config.get_backend(&src_path) { |