Browse Source

Read configuration files

Samuel W. Flint 4 years ago
parent
commit
407aca54aa
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/config.rs

+ 17 - 0
src/config.rs

@@ -1,6 +1,7 @@
 use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 use std::path::PathBuf;
+use std::fs;
 
 #[derive(Serialize, Deserialize)]
 pub struct Config {
@@ -76,3 +77,19 @@ pub fn find_config_file(original: Option<&str>) -> PathBuf {
         Some(p) => return PathBuf::from(&p),
     }
 }
+
+pub fn read_configuration_file(filename: PathBuf) -> Config {
+    let text = fs::read_to_string(filename);
+    match text {
+        Err(_) => {
+            let mut config = Config {
+                repo_types: HashMap::new(),
+                repositories: HashMap::new(),
+                actions: HashMap::new(),
+                groups: HashMap::new()
+            };
+            return config;
+        },
+        Ok(s) => return toml::from_str(&s).unwrap()
+    }
+}