1use std::env;
4use std::fs;
5
6pub const DEFAULT_BONNIE_CFG_PATH: &str = "./bonnie.toml";
8
9pub fn get_cfg() -> Result<String, String> {
11 let path = get_cfg_path()?;
13 let cfg_string = fs::read_to_string(&path);
14 match cfg_string {
15 Ok(cfg_string) => Ok(cfg_string),
16 Err(_) => Err(format!("Error reading Bonnie configuration file at '{}', make sure the file is present in this directory and you have the permissions to read it.", path))
17 }
18}
19
20fn get_cfg_path() -> Result<String, String> {
23 let given_path = env::var("BONNIE_CONF");
25 match given_path {
26 Ok(path) => Ok(path),
27 Err(env::VarError::NotUnicode(_)) => Err(String::from("The path to your Bonnie configuration file given in the 'BONNIE_CONF' environment variable contained invalid characters. Please make sure it only contains valid Unicode.")),
28 Err(env::VarError::NotPresent) => Ok(DEFAULT_BONNIE_CFG_PATH.to_string()) }
30}