use crate::types::Level;
use anyhow::Context;
use serde::Deserialize;
use std::path::Path;
#[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)?)
}
pub fn load(path: &Path) -> anyhow::Result<Self> {
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()))
}
}