Add config file with support for custom commands and git repos, fix #1

This commit is contained in:
Dror Levin
2018-06-08 18:19:07 +03:00
committed by Roey Darwish Dror
parent 13812ec250
commit bf301f51cd
6 changed files with 153 additions and 13 deletions

31
src/config.rs Normal file
View File

@@ -0,0 +1,31 @@
use directories;
use failure;
use std::collections::BTreeMap;
use std::fs;
use toml;
#[derive(Deserialize, Default)]
pub struct Config {
commands: Option<BTreeMap<String, String>>,
git_repos: Option<Vec<String>>,
}
impl Config {
pub fn read() -> Result<Config, failure::Error> {
let base_dirs = directories::BaseDirs::new();
let config_path = base_dirs.config_dir().join("topgrade.toml");
if !config_path.exists() {
return Ok(Default::default());
}
Ok(toml::from_str(&fs::read_to_string(config_path)?)?)
}
pub fn commands(&self) -> &Option<BTreeMap<String, String>> {
&self.commands
}
pub fn git_repos(&self) -> &Option<Vec<String>> {
&self.git_repos
}
}