use crate::fns::fn_io;
use once_cell::sync::OnceCell;
use std::error::Error;
use toml::Value;
type Result = ::std::result::Result<(), Box<dyn Error>>;
pub static DB_LOCATION: OnceCell<String> = OnceCell::new();
pub static DATA_FROM: OnceCell<String> = OnceCell::new();
pub static DATA_TIDY: OnceCell<String> = OnceCell::new();
pub fn set_conf() -> Result {
let mut s = String::from("");
if let Ok(st) = fn_io::f_string("./.temporary/config.toml") {
s = st;
}
let toml_info: Value = toml::from_str(&s)?;
if let Some(from) = toml_info["data"]["from"].as_str() {
DATA_FROM.get_or_init(|| from.to_string());
}
if let Some(tidy) = toml_info["data"]["tidy"].as_str() {
DATA_TIDY.get_or_init(|| tidy.to_string());
}
if let Some(location) = toml_info["db"]["location"].as_str() {
DB_LOCATION.get_or_init(|| location.to_string());
}
Ok(())
}