use core::errors::*;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use toml;
#[derive(Debug, Deserialize)]
pub struct Repository {
pub index: Option<String>,
pub objects: Option<String>,
}
impl Default for Repository {
fn default() -> Repository {
Repository {
index: None,
objects: None,
}
}
}
#[derive(Debug, Deserialize)]
pub struct Config {
pub repository: Option<Repository>,
pub repo_dir: Option<PathBuf>,
pub cache_home: Option<PathBuf>,
}
pub fn read_config<P: AsRef<Path>>(path: P) -> Result<Config> {
let path = path.as_ref();
let mut f = File::open(path)?;
let mut content = String::new();
f.read_to_string(&mut content)?;
let config: Config = toml::from_str(content.as_str())
.map_err(|e| format!("{}: bad config: {}", path.display(), e))?;
Ok(config)
}