libkelp/lib/config/
loader.rs1use crate::lib::structs::config::KelpDotConfig;
2use anyhow::Context;
3use kelpdot_macros::*;
4use std::path::Path;
5pub fn load_cfg(root: String) -> anyhow::Result<KelpDotConfig> {
7 if !Path::new(&format!("{}/kelp.yaml", root)).exists() {
8 red_print!("File {}/kelp.yaml not found!", root);
9 std::process::exit(1);
10 }
11 debug_print!("Loading config {}/kelp.yaml", root);
12 let cfg: KelpDotConfig = serde_yaml::from_str(
13 &std::fs::read_to_string(format!("{}/kelp.yaml", root))
14 .with_context(|| red!("Unable to read config file!"))?,
15 )
16 .with_context(|| red!("Unable to parse config file!"))?;
17 Ok(cfg)
18}