1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::env;
use std::fs;
pub const DEFAULT_BONNIE_CFG_PATH: &str = "./bonnie.toml";
pub fn get_cfg() -> Result<String, String> {
let path = get_cfg_path()?;
let cfg_string = fs::read_to_string(&path);
match cfg_string {
Ok(cfg_string) => Ok(cfg_string),
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))
}
}
fn get_cfg_path() -> Result<String, String> {
let given_path = env::var("BONNIE_CONF");
match given_path {
Ok(path) => Ok(path),
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.")),
Err(env::VarError::NotPresent) => Ok(DEFAULT_BONNIE_CFG_PATH.to_string())
}
}