corge/tool/
configuration_parser.rs

1use crate::config::Config;
2use anyhow::{Context, Result};
3use std::fs;
4use std::path::PathBuf;
5
6pub struct ConfigurationParser {
7    project_directory: PathBuf,
8}
9
10impl ConfigurationParser {
11    pub fn new(project_directory: PathBuf) -> Self {
12        Self {
13            project_directory,
14        }
15    }
16
17    pub fn parse(&self) -> Result<Config> {
18        let config_path: PathBuf = self.project_directory.join("build.yaml");
19
20        log::info!("Parsing configuration file {:?}", &config_path);
21
22        let config_str: String = fs::read_to_string(config_path)
23            .context("Failed to read 'build.yaml' file")?;
24
25        let config: Config = serde_yaml::from_str(&config_str)
26            .context("Failed to parse 'build.yaml' file")?;
27
28        Ok(config)
29    }
30}