Ver código fonte

Add repository configuration

Samuel W. Flint 5 anos atrás
pai
commit
00cbc425f2
2 arquivos alterados com 47 adições e 0 exclusões
  1. 20 0
      src/main.rs
  2. 27 0
      src/repository.rs

+ 20 - 0
src/main.rs

@@ -36,6 +36,26 @@ fn main() {
                     let location = env::current_dir().unwrap().to_str().unwrap().to_string();
                     repository::register(&mut configuration, &name, location, type_name, option_strings);
                 },
+                Some("config") => if let Some(matches) = matches.subcommand_matches("config") {
+                    let name = matches.value_of("name").unwrap().to_string();
+                    if let Some(options) = matches.values_of("options") {
+                        let mut option_strings: Vec<String> = Vec::new();
+                        for str_thing in options {
+                            option_strings.push(str_thing.to_string())
+                        }
+                        repository::update_options(&mut configuration, &name, option_strings);
+                    }
+                    match matches.value_of("autocreate") {
+                        Some("YES") => repository::update_autocreate(&mut configuration, &name, true),
+                        Some("NO") => repository::update_autocreate(&mut configuration, &name, false),
+                        _ => {}
+                    }
+                    match matches.value_of("disable") {
+                        Some("YES") => repository::update_disabled(&mut configuration, &name, true),
+                        Some("NO") => repository::update_disabled(&mut configuration, &name, false),
+                        _ => {}
+                    }
+                },
                 Some("show") => if let Some(matches) = matches.subcommand_matches("show") {
                     let name = matches.value_of("name").unwrap().to_string();
                     let repository = configuration.repositories.get(&name);

+ 27 - 0
src/repository.rs

@@ -37,6 +37,33 @@ pub fn register(config: &mut Config, name: &String, location: String, repo_type:
     config.repositories.insert(name.to_string(), repo);
 }
 
+pub fn update_disabled(config: &mut Config, name: &String, value: bool) {
+    let repo = config.repositories.get_mut(&name.to_string());
+    match repo {
+        Some(repo) => repo.disabled = value,
+        None => panic!("No known repository named \"{}\".", name)
+    }
+}
+
+pub fn update_autocreate(config: &mut Config, name: &String, value: bool) {
+    let repo = config.repositories.get_mut(&name.to_string());
+    match repo {
+        Some(repo) => repo.auto_create = value,
+        None => panic!("No known repository named \"{}\".", name)
+    }
+}
+
+pub fn update_options(config: &mut Config, name: &String, options_strings: Vec<String>) {
+    let repo: Option<&mut Repository> = config.repositories.get_mut(&name.to_string());
+    match repo {
+        Some(repo) => for option in options_strings {
+            let option_pair: Vec<&str> = option.split("=").collect();
+            repo.options.insert(option_pair[0].to_string(), option_pair[1].to_string());
+        }
+        None => panic!("No known repository named \"{}\".", name)
+    }
+}
+
 impl fmt::Display for Repository {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "Repository {}:\n\tPath: {}\n\tType: {}\n\tDisabled: {}\n\tOptions:\n",