use serde::{Deserialize, Serialize};
use std::fs;
use crate::errors::FormatterError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub remove_extra_spaces: bool,
pub detect_headings: bool,
pub detect_lists: bool,
pub custom_patterns: Vec<String>,
}
impl Default for Config {
fn default() -> Self {
Self {
remove_extra_spaces: true,
detect_headings: true,
detect_lists: true,
custom_patterns: vec![],
}
}
}
impl Config {
pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self, FormatterError> {
let contents = fs::read_to_string(path)?;
let config: Self = if contents.trim_start().starts_with('{') {
serde_json::from_str(&contents)?
} else {
toml::from_str(&contents)?
};
Ok(config)
}
}