booktyping_core/
config.rs1use anyhow::Result;
2use std::path::{Path, PathBuf};
3use v_utils::macros::MyConfigPrimitives;
4
5#[derive(Clone, Debug, Default, MyConfigPrimitives)]
7pub struct AppConfig {
8 pub myopia: bool,
9 pub library: PathBuf,
10}
11
12impl AppConfig {
13 pub fn read(path: &Path) -> Result<Self> {
15 let settings = {
16 if path.exists() {
17 let builder = config::Config::builder().add_source(config::File::with_name(path.to_str().unwrap()));
18 let raw: config::Config = builder.build()?;
19 raw.try_deserialize()?
20 } else {
21 AppConfig::default()
22 }
23 };
24
25 Ok(settings)
26 }
27}