kagami/
config_file_parser.rs1use crate::Config;
2use log::{debug, trace};
3use std::error::Error;
4use std::fs;
5
6pub fn parse_config_file(file_path: impl Into<String>) -> Result<Config, Box<dyn Error>> {
7 let file_path = file_path.into();
8 debug!("Reading the config file `{}`.", file_path);
9
10 let config_content = fs::read_to_string(&file_path)?;
11 trace!("Read {} bytes from `{}`.", config_content.len(), file_path);
12
13 let parsed_config: Config = yaml_serde::from_str(config_content.as_str())?;
14 debug!(
15 "Parsed the config file, {} targets are defined.",
16 parsed_config.targets.len()
17 );
18 trace!("Parsed config: {:?}.", parsed_config);
19
20 Ok(parsed_config)
21}