diff options
author | Ruben Pollan | 2018-12-10 18:25:47 +0100 |
---|---|---|
committer | Ruben Pollan | 2018-12-10 18:26:38 +0100 |
commit | 7ffa8632502cfa89aa3341d31f90e68c1a25f3e2 (patch) | |
tree | 9bd05d88edbc2ee295d9549d73b7638435cc4f9c | |
parent | 8a15ad89d7df16c9a82721bae1e9ba8d5ab02dd2 (diff) |
Add the missing config file
-rw-r--r-- | src/config.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..7280aed --- /dev/null +++ b/src/config.rs @@ -0,0 +1,28 @@ +use std::fs::File; +use std::io::Read; +use dirs; +use toml; + +use errors::ConfigError; + +const CONFIG_NAME: &str = "almanac.toml"; + +#[derive(Deserialize)] +pub struct Config { + pub cals: Vec<String>, +} + +impl Config { + pub fn parse() -> Result<Config, ConfigError> { + let config_path = match dirs::config_dir() { + Some(path) => path, + None => return Err(ConfigError::MissingPath), + }.join(CONFIG_NAME); + + let mut file = File::open(&config_path)?; + let mut toml_str = String::new(); + file.read_to_string(&mut toml_str)?; + + Ok(toml::from_str(&toml_str)?) + } +} |