Browse Source

Add configuration

Samuel W. Flint 3 years ago
parent
commit
1433d422c0
2 changed files with 90 additions and 1 deletions
  1. 55 1
      src/lib/repotype.rs
  2. 35 0
      src/main.rs

+ 55 - 1
src/lib/repotype.rs

@@ -40,7 +40,61 @@ pub fn add(config: &mut Config, name: &String, description: &String, create: &St
     config.repo_types.insert(name.to_string(), repo_type);
 }
 
-// TODO add configuration
+pub fn update_description(config: &mut Config, name: &String, description: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.description = description.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_create(config: &mut Config, name: &String, create: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.create = create.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_inward(config: &mut Config, name: &String, inward: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.inward = inward.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_outward(config: &mut Config, name: &String, outward: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.outward = outward.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_status(config: &mut Config, name: &String, status: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.status = status.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_pre_inward(config: &mut Config, name: &String, pre_inward: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.pre_inward = pre_inward.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_post_inward(config: &mut Config, name: &String, post_inward: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.post_inward = post_inward.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
+
+pub fn update_post_outward(config: &mut Config, name: &String, post_outward: &String) {
+    match config.repo_types.get_mut(&name.to_string()) {
+        Some(repo_type) => repo_type.post_outward = post_outward.to_string(),
+        None => panic!("No known repository type named \"{}\".", name)
+    }
+}
 
 impl fmt::Display for RepoType {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

+ 35 - 0
src/main.rs

@@ -181,6 +181,41 @@ fn main() {
                     };
                     repotype::add(&mut configuration, &name, &description, &create, &inward, &outward, &status, &pre_inward, &post_inward, &post_outward);
                 },
+                Some("config") => if let Some(matches) = matches.subcommand_matches("config") {
+                    let name = matches.value_of("name").unwrap().to_string();
+                    match matches.value_of("description") {
+                        Some(description) => repotype::update_description(&mut configuration, &name, &description.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("create") {
+                        Some(create) => repotype::update_create(&mut configuration, &name, &create.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("inward") {
+                        Some(inward) => repotype::update_inward(&mut configuration, &name, &inward.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("outward") {
+                        Some(outward) => repotype::update_outward(&mut configuration, &name, &outward.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("status") {
+                        Some(status) => repotype::update_status(&mut configuration, &name, &status.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("pre_inward") {
+                        Some(pre_inward) => repotype::update_pre_inward(&mut configuration, &name, &pre_inward.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("post_inward") {
+                        Some(post_inward) => repotype::update_post_inward(&mut configuration, &name, &post_inward.to_string()),
+                        _ => {}
+                    }
+                    match matches.value_of("post_outward") {
+                        Some(post_outward) => repotype::update_post_outward(&mut configuration, &name, &post_outward.to_string()),
+                        _ => {}
+                    }
+                }
                 Some("show") => if let Some(matches) = matches.subcommand_matches("show") {
                     let name = matches.value_of("name").unwrap().to_string();
                     let repo_type = configuration.repo_types.get(&name);