refractr/src/config.rs

48 lines
987 B
Rust
Raw Normal View History

2025-02-15 22:11:08 -07:00
use std::io::Read;
use std::path::PathBuf;
use std::fs::File;
use toml;
use serde_derive::Deserialize;
#[derive(Deserialize)]
pub struct Config {
from: String,
2025-02-15 22:11:08 -07:00
to: Vec<String>,
branches: Vec<String>,
git: Git,
schedule: Schedule
}
#[derive(Deserialize)]
struct Git {
ssh_identity_file: String,
}
#[derive(Deserialize)]
struct Schedule {
enabled: bool,
duration: i32,
}
pub fn read_config(paths: Vec<PathBuf>) -> Vec<Config> {
let mut configs: Vec<Config> = vec![];
for path in paths {
let mut data = String::new();
let mut file = match File::open(path.as_path()) {
Err(e) => panic!("unable to open {}: {}", path.as_path().display(), e),
Ok(file) => file
};
2025-02-15 22:11:08 -07:00
if let Err(e) = file.read_to_string(&mut data) {
panic!("unable to read {}: {}", path.as_path().display(), e)
}
configs.push(verify_config(toml::from_str(&data).unwrap()));
2025-02-15 22:11:08 -07:00
}
return configs;
}
fn verify_config(config: Config) -> Config {
2025-02-15 22:11:08 -07:00
return config;
}