Kaynağa Gözat

Remove repos from groups

Samuel W. Flint 4 yıl önce
ebeveyn
işleme
e731d3b7ae
2 değiştirilmiş dosya ile 12 ekleme ve 1 silme
  1. 7 1
      src/lib/group.rs
  2. 5 0
      src/main.rs

+ 7 - 1
src/lib/group.rs

@@ -36,7 +36,13 @@ pub fn add_action(config: &mut Config, name: &String, action: &String) {
     }
 }
 
-// TODO: add repo removal
+pub fn remove_repo(config: &mut Config, name: &String, repo: &String) {
+    match config.groups.get_mut(&name.to_string()) {
+        Some(group) => group.members.retain(|r| r != repo),
+        None => panic!("No known group named \"{}\".", name)
+    }
+}
+
 // TODO: add group deletion
 
 impl fmt::Display for Group {

+ 5 - 0
src/main.rs

@@ -125,6 +125,11 @@ fn main() {
                     let action = matches.value_of("action").unwrap().to_string();
                     group::add_action(&mut configuration, &name, &action);
                 },
+                Some("remove") => if let Some(matches) = matches.subcommand_matches("remove") {
+                    let name = matches.value_of("name").unwrap().to_string();
+                    let repo = matches.value_of("repo").unwrap().to_string();
+                    group::remove_repo(&mut configuration, &name, &repo);
+                },
                 Some("show") => if let Some(matches) = matches.subcommand_matches("show") {
                     let name = matches.value_of("name").unwrap().to_string();
                     let group = configuration.groups.get(&name);