diff options
| author | Teddy Wing | 2018-10-20 18:42:03 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-10-20 18:42:03 +0200 | 
| commit | 2c6c0e13cebe29a56b56522ef9e6f2ccf33011f7 (patch) | |
| tree | a259d71ad3b6c8dc3f2f5905ad62039428ffb990 | |
| parent | 4e90fd77eb0ef56a39c2af6fae068fb91782fd0d (diff) | |
| download | dome-key-map-2c6c0e13cebe29a56b56522ef9e6f2ccf33011f7.tar.bz2 | |
get_config(): Don't fail if the XDG config directory isn't present
In that case, we should return the default config.
| -rw-r--r-- | src/config.rs | 22 | 
1 files changed, 13 insertions, 9 deletions
| diff --git a/src/config.rs b/src/config.rs index 750b47a..feaf578 100644 --- a/src/config.rs +++ b/src/config.rs @@ -67,16 +67,20 @@ pub fn parse_args<'a>(args: &[String], config: &'a mut Config) -> &'a mut Config  }  pub fn get_config() -> Result<Config> { -    let xdg_dirs = xdg::BaseDirectories::with_prefix("dome-key")?; -    let config = match xdg_dirs.find_config_file("config.toml") { -        Some(config_file) => { -            let config_str = fs::read_to_string(config_file) -                .chain_err(|| "failed to read config file")?; - -            toml::from_str(&config_str) -                .chain_err(|| "failed to parse config file")? +    let config = match xdg::BaseDirectories::with_prefix("dome-key") { +        Ok(xdg_dirs) => { +            match xdg_dirs.find_config_file("config.toml") { +                Some(config_file) => { +                    let config_str = fs::read_to_string(config_file) +                        .chain_err(|| "failed to read config file")?; + +                    toml::from_str(&config_str) +                        .chain_err(|| "failed to parse config file")? +                }, +                None => Config::default(), +            }          }, -        None => Config::default(), +        Err(_) => Config::default(),      };      Ok(config) | 
