use std::path::Path; use anyhow::Result; use serde::Deserialize; const DEFAULT_CFG: &'static str = include_str!("../config.template.toml"); #[derive(Debug, Deserialize, Clone)] pub struct Config { pub commands: ConfigCommands, } #[derive(Debug, Deserialize, Clone)] pub struct ConfigCommands { pub get_volume: String, pub get_volume_regex: String, } impl Config { pub fn parse(p: &Path) -> Result { if !p.exists() { std::fs::write(p, DEFAULT_CFG)?; } let c = std::fs::read_to_string(p)?; Ok(toml::from_str(c.as_str())?) } pub fn default() -> Self { Self { commands: ConfigCommands { get_volume: String::new(), get_volume_regex: String::new() } } } }