diff options
author | mustafa salih <mustafasalih1991@gmail.com> | 2021-01-16 09:26:06 +0300 |
---|---|---|
committer | mustafa salih <mustafasalih1991@gmail.com> | 2021-01-16 09:26:06 +0300 |
commit | 4f83d10cf86bcc4c2364e7f5f24be34712242b04 (patch) | |
tree | 434dbeded52ced22d6f6f064f7f7f16f7f5bbbf0 /src/config.rs | |
parent | 6a349a0e0282e56b03adbe02b41bfaf0cc3213f1 (diff) |
added some checks
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs index b54f8f1..5c76c6a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,8 +21,21 @@ pub fn load_config() -> Result<Config, Error> { } }; file.read_to_string(&mut data)?; - let yml_content = &YamlLoader::load_from_str(&data).unwrap()[0]; - let config = parse_config(yml_content); + + // checking if rsblocks.yml is empty + let yml_content = match YamlLoader::load_from_str(&data) { + Ok(content) => { + if content.len() > 0 { + content[0].clone() + } else { + eprintln!("configuration file looks empty, loading defaults!"); + return Ok(load_defaults()); + } + } + _ => return Ok(load_defaults()), + }; + + let config = parse_config(&yml_content); Ok(config) } |