refractr/src/config.rs

41 lines
839 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;
use std::process;
#[derive(Deserialize)]
pub struct Config {
from: Vec<String>,
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(path: PathBuf) -> Config {
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
};
if let Err(e) = file.read_to_string(&mut data) {
panic!("unable to read {}: {}", path.as_path().display(), e)
}
let config: Config = toml::from_str(&data).unwrap();
return config;
}