use std::fs;
use std::process::exit;
use toml;
use super::models::Root;
pub fn toml_parser(file_path: String) -> Result <Root, std::io::Error> {
let filename = file_path.to_string();
let contents = match fs::read_to_string(&filename) {
Ok(c) => c,
Err(e) => {
eprintln!("Could not read file: {}: {}", filename, e);
exit(1);
}
};
let data: Root = match toml::from_str(&contents) {
Ok(d) => d,
Err(e) => {
eprintln!("Unable to load data from {}", e);
exit(1);
}
};
Ok(data)
}