use crate::types::Level;
use serde::Deserialize;
#[derive(Debug, Clone, Default, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub level: Option<Level>,
pub preset: Option<String>,
#[serde(default)]
pub models: Vec<String>,
#[serde(default)]
pub rules: Vec<String>,
#[serde(default)]
pub stock_phrases: Vec<String>,
}
impl Config {
pub fn from_toml(text: &str) -> anyhow::Result<Self> {
Ok(toml::from_str(text)?)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn load(path: &std::path::Path) -> anyhow::Result<Self> {
use anyhow::Context;
let text = std::fs::read_to_string(path)
.with_context(|| format!("cannot read config file {}", path.display()))?;
Self::from_toml(&text).with_context(|| format!("invalid config file {}", path.display()))
}
}