瀏覽代碼

Move stuff around

Samuel W. Flint 5 年之前
父節點
當前提交
37a3fb06bd
共有 9 個文件被更改,包括 64 次插入24 次删除
  1. 1 1
      src/lib/action.rs
  2. 8 13
      src/lib/config.rs
  3. 16 0
      src/lib/group.rs
  4. 5 0
      src/lib/mod.rs
  5. 1 1
      src/lib/repository.rs
  6. 1 1
      src/lib/repotype.rs
  7. 11 0
      src/lib/run.rs
  8. 11 0
      src/lib/test.rs
  9. 10 8
      src/main.rs

+ 1 - 1
src/action.rs → src/lib/action.rs

@@ -20,6 +20,6 @@ impl fmt::Display for Action {
                self.description,
                self.command,
                self.disabled
-        );
+        )
     }
 }

+ 8 - 13
src/config.rs → src/lib/config.rs

@@ -9,18 +9,23 @@ use std::io::Write;
 
 use home::home_dir;
 
-use crate::repository::{
+
+use crate::lib::repository::{
     Repository
 };
 
-use crate::repotype::{
+use crate::lib::repotype::{
     RepoType
 };
 
-use crate::action::{
+use crate::lib::action::{
     Action
 };
 
+use crate::lib::group::{
+    Group
+};
+
 #[derive(Serialize, Deserialize)]
 pub struct Config {
     #[serde(rename(serialize = "repo_type", deserialize = "repo_type"), default)]
@@ -33,16 +38,6 @@ pub struct Config {
     groups: HashMap<String, Group>,
 }
 
-#[derive(Serialize, Deserialize)]
-pub struct Group {
-    #[serde(default)]
-    name: String,
-    #[serde(default)]
-    actions_after: Vec<String>,
-    #[serde(default)]
-    members: Vec<String>,
-}
-
 pub fn find_config_file(original: Option<&str>) -> PathBuf {
     match original {
         None => {

+ 16 - 0
src/lib/group.rs

@@ -0,0 +1,16 @@
+use serde::{Deserialize, Serialize};
+use std::fmt;
+
+#[derive(Serialize, Deserialize)]
+pub struct Group {
+    #[serde(default)]
+    name: String,
+    #[serde(default)]
+    actions_after: Vec<String>,
+    #[serde(default)]
+    members: Vec<String>,
+}
+
+/*impl fmt::Display for Group {
+    
+}*/

+ 5 - 0
src/lib/mod.rs

@@ -0,0 +1,5 @@
+mod action;
+pub mod config;
+mod group;
+pub mod repository;
+mod repotype;

+ 1 - 1
src/repository.rs → src/lib/repository.rs

@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 use std::fmt;
 
-use crate::config::Config;
+use crate::lib::config::Config;
 
 #[derive(Serialize, Deserialize)]
 pub struct Repository {

+ 1 - 1
src/repotype.rs → src/lib/repotype.rs

@@ -22,6 +22,6 @@ impl fmt::Display for RepoType {
                self.description,
                self.create,
                self.inward,
-               self.outward);
+               self.outward)
     }
 }

+ 11 - 0
src/lib/run.rs

@@ -0,0 +1,11 @@
+use clap::Values;
+use config::{
+    Config,
+    Repository
+}
+
+pub fn run(names: Values<'_>) {
+    for name in names {
+        println!("Name: {}", name)
+    }
+}

+ 11 - 0
src/lib/test.rs

@@ -0,0 +1,11 @@
+pub fn rename_repository(config: &mut Config, name: &String, newName: &String) {
+    let mut repo = config.repositories.get_mut(&name.to_string());
+    match repo {
+        Some(repo) => {
+            repo.name = newName.to_string();
+            config.repositories.insert(newName.to_string(), repo);
+            config.repositories.remove(&name.to_string());
+        },
+        None => panic!("No known repostory named \"{}\".", name)
+    }
+}

+ 10 - 8
src/main.rs

@@ -4,15 +4,17 @@ use clap::App;
 
 use std::env;
 
-mod config;
-use config::{
-    find_config_file,
-    read_configuration_file,
-    write_configuration_file,
-    Config
-};
+mod lib;
 
-mod repository;
+use crate::lib::{
+    config::{
+        find_config_file,
+        read_configuration_file,
+        write_configuration_file,
+        Config
+    },
+    repository
+};
 
 fn main() {
     let yaml = load_yaml!("cli.yml");