Browse Source

Add basic repotype creation

Samuel W. Flint 3 years ago
parent
commit
585db8cdd5
5 changed files with 107 additions and 4 deletions
  1. 32 0
      src/cli.yml
  2. 1 1
      src/lib/config.rs
  3. 1 1
      src/lib/mod.rs
  4. 25 1
      src/lib/repotype.rs
  5. 48 1
      src/main.rs

+ 32 - 0
src/cli.yml

@@ -193,6 +193,22 @@ subcommands:
                   long: outward
                   takes_value: true
                   help: Command to perform outward sync of a repository of type NAME
+              - status:
+                  long: status
+                  takes_value: true
+                  help: Command to display status of repository
+              - pre_inward:
+                  long: pre-inward
+                  takes_value: true
+                  help: Command describing potential pre-inward action
+              - post_inward:
+                  long: post-inward
+                  takes_value: true
+                  help: Command describing post-inward action
+              - post_outward:
+                  long: post-outward
+                  takes_value: true
+                  help: Command describing post-outward action
         - config:
             about: Configure a repository type
             args:
@@ -217,6 +233,22 @@ subcommands:
                   long: outward
                   takes_value: true
                   help: Command to perform outward sync of a repository of type NAME
+              - status:
+                  long: status
+                  takes_value: true
+                  help: Command to display status of repository
+              - pre_inward:
+                  long: pre-inward
+                  takes_value: true
+                  help: Command describing potential pre-inward action
+              - post_inward:
+                  long: post-inward
+                  takes_value: true
+                  help: Command describing post-inward action
+              - post_outward:
+                  long: post-outward
+                  takes_value: true
+                  help: Command describing post-outward action
         - show:
             about: Show information about a type
             args:

+ 1 - 1
src/lib/config.rs

@@ -29,7 +29,7 @@ use crate::lib::group::{
 #[derive(Serialize, Deserialize)]
 pub struct Config {
     #[serde(rename(serialize = "repo_type", deserialize = "repo_type"), default)]
-    repo_types: HashMap<String, RepoType>,
+    pub repo_types: HashMap<String, RepoType>,
     #[serde(rename(serialize = "repository", deserialize = "repository"), default)]
     pub repositories: HashMap<String, Repository>,
     #[serde(rename(serialize = "action", deserialize = "action"), default)]

+ 1 - 1
src/lib/mod.rs

@@ -2,4 +2,4 @@ pub mod action;
 pub mod config;
 pub mod group;
 pub mod repository;
-mod repotype;
+pub mod repotype;

+ 25 - 1
src/lib/repotype.rs

@@ -1,6 +1,8 @@
 use serde::{Deserialize, Serialize};
 use std::fmt;
 
+use crate::lib::config::Config;
+
 #[derive(Serialize, Deserialize)]
 pub struct RepoType {
     #[serde(default)]
@@ -13,9 +15,31 @@ pub struct RepoType {
     inward: String,
     #[serde(default)]
     outward: String,
+    #[serde(default)]
+    status: String,
+    #[serde(default)]
+    pre_inward: String,
+    #[serde(default)]
+    post_inward: String,
+    #[serde(default)]
+    post_outward: String,
+}
+
+pub fn add(config: &mut Config, name: &String, description: &String, create: &String, inward: &String, outward: &String, status: &String, pre_inward: &String, post_inward: &String, post_outward: &String) {
+    let repo_type = RepoType {
+        name: name.to_string(),
+        description: description.to_string(),
+        create: create.to_string(),
+        inward: inward.to_string(),
+        outward: outward.to_string(),
+        status: status.to_string(),
+        pre_inward: pre_inward.to_string(),
+        post_inward: post_inward.to_string(),
+        post_outward: post_outward.to_string()
+    };
+    config.repo_types.insert(name.to_string(), repo_type);
 }
 
-// TODO add creation
 // TODO add configuration
 
 impl fmt::Display for RepoType {

+ 48 - 1
src/main.rs

@@ -15,7 +15,8 @@ use crate::lib::{
     },
     repository,
     action,
-    group
+    group,
+    repotype
 };
 
 fn main() {
@@ -145,6 +146,52 @@ fn main() {
                 _ => panic!("Something has gone horribly wrong...")
             }
         },
+        Some("type") => if let Some(matches) = matches.subcommand_matches("type") {
+            match matches.subcommand_name() {
+                Some("create") => if let Some(matches) = matches.subcommand_matches("create") {
+                    let name = matches.value_of("name").unwrap().to_string();
+                    let description = matches.value_of("description").unwrap().to_string();
+                    let create = match matches.value_of("create") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    let inward = match matches.value_of("inward") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    let outward = match matches.value_of("outward") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    let status = match matches.value_of("status") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    let pre_inward = match matches.value_of("pre_inward") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    let post_inward = match matches.value_of("post_inward") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    let post_outward = match matches.value_of("post_outward") {
+                        Some(thing) => thing.to_string(),
+                        None => "".to_string()
+                    };
+                    repotype::add(&mut configuration, &name, &description, &create, &inward, &outward, &status, &pre_inward, &post_inward, &post_outward);
+                },
+                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);
+                    match repo_type {
+                        Some(repo_type) => println!("{}", repo_type),
+                        None => eprintln!("No known repo type named \"{}\".", name)
+                    }
+                },
+                _ => panic!("Something has gone horribly wrong...")
+            }
+        },
         Some(thing) => println!("{}", thing),
         _ => println!("No subcommand."),
     }