Browse Source

Add ability to add repos to groups

Samuel W. Flint 5 years ago
parent
commit
afde6fc83d
2 changed files with 11 additions and 0 deletions
  1. 7 0
      src/lib/group.rs
  2. 4 0
      src/main.rs

+ 7 - 0
src/lib/group.rs

@@ -22,6 +22,13 @@ pub fn add(config: &mut Config, name: &String) {
     config.groups.insert(name.to_string(), group);
 }
 
+pub fn add_repo(config: &mut Config, name: &String, repo: &String) {
+    match config.groups.get_mut(&name.to_string()) {
+        Some(group) => group.members.push(repo.to_string()),
+        None => panic!("No known group named \"{}\".", name)
+    }
+}
+
 impl fmt::Display for Group {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "Group {}:\n\tRepos:\n", self.name)?;

+ 4 - 0
src/main.rs

@@ -115,6 +115,10 @@ fn main() {
                     let name = matches.value_of("name").unwrap().to_string();
                     group::add(&mut configuration, &name);
                 },
+                Some("add") => if let Some(matches) = matches.subcommand_matches("add") {
+                    let name = matches.value_of("name").unwrap().to_string();
+                    let repo = matches.value_of("repo").unwrap().to_string();
+                    group::add_repo(&mut configuration, &name, &repo);
                 },
                 Some("show") => if let Some(matches) = matches.subcommand_matches("show") {
                     let name = matches.value_of("name").unwrap().to_string();