Browse Source

Groups are now runabble

Samuel W. Flint 3 years ago
parent
commit
961801c0dc
2 changed files with 23 additions and 2 deletions
  1. 2 2
      src/lib/group.rs
  2. 21 0
      src/lib/run.rs

+ 2 - 2
src/lib/group.rs

@@ -8,9 +8,9 @@ pub struct Group {
     #[serde(default)]
     name: String,
     #[serde(default)]
-    actions_after: Vec<String>,
+    pub actions_after: Vec<String>,
     #[serde(default)]
-    members: Vec<String>,
+    pub members: Vec<String>,
 }
 
 pub fn add(config: &mut Config, name: &String) {

+ 21 - 0
src/lib/run.rs

@@ -118,3 +118,24 @@ pub fn run_repository_creation(config: &Config, name: String) {
         None => panic!("No known repository named \"{}\".", name)
     }
 }
+
+pub fn run_group(config: &Config, name: String) {
+    let group = config.groups.get(&name.to_string());
+    match group {
+        Some(group) => {
+            for member in &group.members {
+                if config.repositories.contains_key(member) {
+                    run_repository_sync(&config, member.to_string());
+                } else if config.groups.contains_key(member) {
+                    run_group(&config, member.to_string());
+                } else {
+                    println!("\"{}\" is neither a group nor a repository.", member);
+                }
+            }
+            for action in &group.actions_after {
+                run_action(&config, action.to_string());
+            }
+        },
+        None => panic!("No known group named \"{}\".", name)
+    }
+}