use std::path::PathBuf;
use color_eyre::Report;
use serde::Deserialize;
#[derive(Default, Clone, Deserialize, Debug)]
pub struct BagexConfig {
pub path: Option<Vec<std::path::PathBuf>>,
pub env: Option<toml::Value>,
pub exe: Option<toml::Value>,
pub clear_env: Option<bool>,
}
impl BagexConfig {
pub fn validate(self: BagexConfig) -> bool {
if let toml::Value::Table(env_table) = self.env.unwrap() {
for (env_name, info) in env_table {
if let toml::Value::Table(value_exe_pairs) = info {
for (_value, exes) in value_exe_pairs {
if let toml::Value::Array(_exes) = exes {
continue;
} else {
log::error!("Value of variable {} is expanded as a toml table", env_name);
log::error!(
"because it contains character '.' (dot)."
);
log::error!("Quote the value to fix this");
return false;
}
}
}
}
}
true
}
pub fn from_pathbuf(path: PathBuf) -> Result<BagexConfig, Report> {
let confstr = std::fs::read_to_string(path)?;
Ok(toml::from_str(&confstr)?)
}
}