Browse Source

Drop groups

Samuel W. Flint 3 years ago
parent
commit
c9fad64380
3 changed files with 20 additions and 6 deletions
  1. 8 0
      src/cli.yml
  2. 3 1
      src/lib/group.rs
  3. 9 5
      src/main.rs

+ 8 - 0
src/cli.yml

@@ -148,6 +148,14 @@ subcommands:
                   value_name: REPO_NAME
                   help: The name of the repo
                   required: true
+        - drop:
+            about: Remove a group
+            args:
+              - group:
+                  index: 1
+                  value_name: GROUP_NAME
+                  help: The name of the group
+                  required: true
         - show:
             about: Show information about a group
             args:

+ 3 - 1
src/lib/group.rs

@@ -43,7 +43,9 @@ pub fn remove_repo(config: &mut Config, name: &String, repo: &String) {
     }
 }
 
-// TODO: add group deletion
+pub fn remove_group(config: &mut Config, name: &String) {
+    config.groups.remove(&name.to_string());
+}
 
 impl fmt::Display for Group {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

+ 9 - 5
src/main.rs

@@ -112,26 +112,30 @@ fn main() {
         Some("group") => if let Some(matches) = matches.subcommand_matches("group") {
             match matches.subcommand_name() {
                 Some("create") => if let Some(matches) = matches.subcommand_matches("create") {
-                    let name = matches.value_of("name").unwrap().to_string();
+                    let name = matches.value_of("group").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 name = matches.value_of("group").unwrap().to_string();
                     let repo = matches.value_of("repo").unwrap().to_string();
                     group::add_repo(&mut configuration, &name, &repo);
                 },
                 Some("act") => if let Some(matches) = matches.subcommand_matches("act") {
-                    let name = matches.value_of("name").unwrap().to_string();
+                    let name = matches.value_of("group").unwrap().to_string();
                     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 name = matches.value_of("group").unwrap().to_string();
                     let repo = matches.value_of("repo").unwrap().to_string();
                     group::remove_repo(&mut configuration, &name, &repo);
                 },
+                Some("drop") => if let Some(matches) = matches.subcommand_matches("drop") {
+                    let name = matches.value_of("group").unwrap().to_string();
+                    group::remove_group(&mut configuration, &name);
+                }
                 Some("show") => if let Some(matches) = matches.subcommand_matches("show") {
-                    let name = matches.value_of("name").unwrap().to_string();
+                    let name = matches.value_of("group").unwrap().to_string();
                     let group = configuration.groups.get(&name);
                     match group {
                         Some(group) => println!("{}", group),