Browse Source

Add basic handling of additional commands

Samuel W. Flint 3 years ago
parent
commit
45a34a276f
2 changed files with 77 additions and 1 deletions
  1. 54 0
      src/cli.yml
  2. 23 1
      src/main.rs

+ 54 - 0
src/cli.yml

@@ -260,6 +260,60 @@ subcommands:
                   long: post-outward
                   takes_value: true
                   help: Command describing post-outward action
+        - command:
+            about: Manage commands in a repo type
+            settings:
+              - SubcommandRequired
+            subcommands:
+              - add:
+                  about: Create a new command
+                  args:
+                    - type:
+                        index: 1
+                        value_name: REPO_TYPE
+                        help: Repository Type
+                        required: true
+                    - name:
+                        index: 2
+                        value_name: COMMAND_NAME
+                        help: Command Name
+                        required: true
+                    - command:
+                        index: 3
+                        value_name: COMMAND
+                        help: Command
+                        required: true
+              - change:
+                  about: Change a command
+                  args:
+                    - type:
+                        index: 1
+                        value_name: REPO_TYPE
+                        help: Repository Type
+                        required: true
+                    - name:
+                        index: 2
+                        value_name: COMMAND_NAME
+                        help: Command Name
+                        required: true
+                    - command:
+                        index: 3
+                        value_name: COMMAND
+                        help: Command
+                        required: true
+              - remove:
+                  about: Remove a command
+                  args:
+                    - type:
+                        index: 1
+                        value_name: REPO_TYPE
+                        help: Repository Type
+                        required: true
+                    - name:
+                        index: 2
+                        value_name: COMMAND_NAME
+                        help: Command Name
+                        required: true
         - show:
             about: Show information about a type
             args:

+ 23 - 1
src/main.rs

@@ -255,7 +255,29 @@ fn main() {
                         Some(post_outward) => repotype::update_post_outward(&mut configuration, &name, &post_outward.to_string()),
                         _ => {}
                     }
-                }
+                },
+                Some("command") => if let Some(matches) = matches.subcommand_matches("command") {
+                    match matches.subcommand_name() {
+                        Some("add") => if let Some(matches) = matches.subcommand_matches("add") {
+                            let type_name = matches.value_of("type").unwrap().to_string();
+                            let name = matches.value_of("name").unwrap().to_string();
+                            let command = matches.value_of("command").unwrap().to_string();
+                            repotype::add_command(&mut configuration, &type_name, &name, &command);
+                        },
+                        Some("change") => if let Some(matches) = matches.subcommand_matches("change") {
+                            let type_name = matches.value_of("type").unwrap().to_string();
+                            let name = matches.value_of("name").unwrap().to_string();
+                            let command = matches.value_of("command").unwrap().to_string();
+                            repotype::change_command(&mut configuration, &type_name, &name, &command);
+                        },
+                        Some("remove") => if let Some(matches) = matches.subcommand_matches("remove") {
+                            let type_name = matches.value_of("type").unwrap().to_string();
+                            let name = matches.value_of("name").unwrap().to_string();
+                            repotype::remove_command(&mut configuration, &type_name, &name);
+                        },
+                        _ => panic!("Something has gone horribly wrong...")
+                    }
+                },
                 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);