Browse Source

Update some repository removal logic

Samuel W. Flint 3 years ago
parent
commit
5f2c349052
7 changed files with 32 additions and 3 deletions
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 1 1
      flake.nix
  4. 8 0
      src/cli.yml
  5. 10 0
      src/lib/group.rs
  6. 7 0
      src/lib/repository.rs
  7. 4 0
      src/main.rs

+ 1 - 1
Cargo.lock

@@ -171,7 +171,7 @@ dependencies = [
 
 [[package]]
 name = "sync-it"
-version = "1.2.2"
+version = "1.2.3"
 dependencies = [
  "clap",
  "home",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "sync-it"
-version = "1.2.2"
+version = "1.2.3"
 authors = ["Samuel W. Flint <swflint@flintfam.org>"]
 edition = "2018"
 

+ 1 - 1
flake.nix

@@ -21,7 +21,7 @@
 
             src = ./.;
 
-            cargoSha256 = "klPkLzqvD94Qm4dNSDTFRCQ+a2EIZxwJgAvcKgIP0Og=";
+            cargoSha256 = "UIf2Mul1aC/y9evSfNb0icjePdJfzTuRWJvO3OgAmXc=";
 
             meta = with pkgs.stdenv.lib; {
               description = "A simple, customizable synchronization tool.";

+ 8 - 0
src/cli.yml

@@ -81,6 +81,14 @@ subcommands:
                   help: Type-specific options
                   multiple: true
                   takes_value: true
+        - remove:
+            about: Remove a repository from the configuration
+            args:
+              - name:
+                  index: 1
+                  value_name: NAME
+                  help: The name of the repository
+                  required: true
         - show:
             about: Show information about a repository
             args:

+ 10 - 0
src/lib/group.rs

@@ -64,9 +64,19 @@ pub fn remove_repo(config: &mut Config, name: &String, repo: &String) {
     }
 }
 
+pub fn remove_repo_from_groups(config: &mut Config, repo: &String) {
+    // let ref tmp_groups = &config.groups;
+    for (_group_name, group) in &mut config.groups {
+        group.members.remove(repo);
+    }
+}
+
 pub fn remove_group(config: &mut Config, name: &String) {
     config.groups.remove(&name.to_string());
     config.is_changed = true;
+    for (_name, group) in &mut config.groups {
+        group.members.remove(name);
+    }
 }
 
 impl fmt::Display for Group {

+ 7 - 0
src/lib/repository.rs

@@ -3,6 +3,7 @@ use std::collections::BTreeMap;
 use std::fmt;
 
 use crate::lib::config::Config;
+use crate::lib::group;
 
 #[derive(Serialize, Deserialize)]
 pub struct Repository {
@@ -72,6 +73,12 @@ pub fn update_options(config: &mut Config, name: &String, options_strings: Vec<S
     }
 }
 
+pub fn remove_repo(mut config: &mut Config, name: &String) {
+    config.repositories.remove(&name.to_string());
+    config.is_changed = true;
+    group::remove_repo_from_groups(&mut config, 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",

+ 4 - 0
src/main.rs

@@ -70,6 +70,10 @@ fn main() {
                         _ => {}
                     }
                 },
+                Some("remove") => if let Some(matches) = matches.subcommand_matches("remove") {
+                    let name = matches.value_of("name").unwrap().to_string();
+                    repository::remove_repo(&mut configuration, &name);
+                },
                 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);