use crate::error::GeneralError; use serde::Deserialize; use std::fs; use std::path::Path; #[derive(Deserialize, Debug)] pub struct Config { pub gitlab: Vec, pub gitea: Vec, pub openproject: OpenProjectConfig, } #[derive(Deserialize, Debug)] pub struct GitlabConfig { pub token: String, pub domain: String, } #[derive(Deserialize, Debug)] pub struct GiteaConfig { pub token: String, pub domain: String, } #[derive(Deserialize, Debug)] pub struct OpenProjectConfig { pub token: String, pub base_url: String, } pub struct BuildConfigError { msg: String, } impl Into for BuildConfigError { fn into(self) -> GeneralError { GeneralError { description: format!("Could not build config: {}", self.msg), } } } pub fn build_config(config_path: &Path) -> Result { let config_path_content = match fs::read_to_string(config_path) { Ok(content) => content, Err(e) => { return Err(BuildConfigError { msg: format!( "Could not read a config file at {:?}, error: {}", config_path, e ), }); } }; let config: Config = toml::from_str(&*config_path_content).expect("Could not parse config"); Ok(config) }