Initial commit

This commit is contained in:
2021-11-15 16:16:15 +01:00
commit f6a51c70cc
12 changed files with 1504 additions and 0 deletions

40
src/config.rs Normal file
View File

@@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};
use super::repo::Repo;
#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub trees: Vec<Tree>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Tree {
pub root: Option<String>,
pub repos: Option<Vec<Repo>>,
}
pub fn read_config(path: &str) -> Result<Config, String> {
let content = match std::fs::read_to_string(&path) {
Ok(s) => s,
Err(e) => {
return Err(format!(
"Error reading configuration file \"{}\": {}",
path, e
))
}
};
let config: Config = match toml::from_str(&content) {
Ok(c) => c,
Err(e) => {
return Err(format!(
"Error parsing configuration file \"{}\": {}",
path, e
))
}
};
Ok(config)
}