From 2c6c0e13cebe29a56b56522ef9e6f2ccf33011f7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 20 Oct 2018 18:42:03 +0200 Subject: get_config(): Don't fail if the XDG config directory isn't present In that case, we should return the default config. --- src/config.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') 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 { - 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) -- cgit v1.2.3