diff --git a/src/git.rs b/src/git.rs index be40c14..72022ea 100644 --- a/src/git.rs +++ b/src/git.rs @@ -33,10 +33,17 @@ pub enum RepoFlags { /// Represents the config.toml file. #[derive(PartialEq, Debug, Serialize, Deserialize)] pub struct Config { - pub repos: Vec, + pub categories: Vec, pub links: Vec, } +#[derive(PartialEq, Debug, Serialize, Deserialize)] +pub struct Category { + pub name: String, + pub flags: Vec, // FIXME: not implemented + pub repos: Vec, +} + /// Contain fields for a single link. #[derive(PartialEq, Debug, Serialize, Deserialize)] pub struct Links { @@ -206,47 +213,59 @@ impl Config { /// Tries to pull all repositories, skips if fail. pub fn pull_all(&self) { debug!("exectuting pull_all"); - for r in self.repos.iter() { - r.pull(); + for category in self.categories.iter() { + for repo in category.repos.iter() { + repo.pull(); + } } } /// Tries to clone all repositories, skips if fail. pub fn clone_all(&self) { debug!("exectuting clone_all"); - for r in self.repos.iter() { - r.clone(); + for category in self.categories.iter() { + for repo in category.repos.iter() { + repo.clone(); + } } } /// Tries to add all work in all repositories, skips if fail. pub fn add_all(&self) { debug!("exectuting clone_all"); - for r in self.repos.iter() { - r.add_all(); + for category in self.categories.iter() { + for repo in category.repos.iter() { + repo.add_all(); + } } } /// Tries to commit all repositories one at a time, skips if fail. pub fn commit_all(&self) { debug!("exectuting clone_all"); - for r in self.repos.iter() { - r.commit(); + for category in self.categories.iter() { + for repo in category.repos.iter() { + repo.commit(); + } } } /// Tries to commit all repositories with msg, skips if fail. pub fn commit_all_msg(&self, msg: &String) { debug!("exectuting clone_all"); - for r in self.repos.iter() { - r.commit_with_msg(msg); + for category in self.categories.iter() { + for repo in category.repos.iter() { + repo.commit_with_msg(msg); + } } } /// Tries to pull, add all, commit with msg "quick commit", and push all /// repositories, skips if fail. pub fn quick(&self, msg: &String) { debug!("exectuting quick"); - for r in self.repos.iter() { - r.pull(); - r.add_all(); - r.commit_with_msg(msg); - r.push(); + for category in self.categories.iter() { + for repo in category.repos.iter() { + repo.pull(); + repo.add_all(); + repo.commit_with_msg(msg); + repo.push(); + } } } diff --git a/src/main.rs b/src/main.rs index d0273aa..07275b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,8 +71,8 @@ fn main() { #[cfg(test)] mod config { use crate::*; - use git::GitRepo; use git::RepoFlags::{Clone, Push}; + use git::{Category, GitRepo}; use relative_path::RelativePath; use std::env::current_dir; use std::fs::File; @@ -80,16 +80,28 @@ mod config { #[test] fn init_config() { let _config = Config { - repos: vec![], + categories: vec![], links: vec![], }; } #[test] fn init_config_populate() { - let mut config = Config { + let defaultCategory = Category { + name: "Default".to_string(), + flags: vec![], repos: vec![], + }; + let mut config = Config { + categories: vec![defaultCategory], links: vec![], }; + for _ in 0..=5 { + let category = Category { + name: "ehh".to_string(), + flags: vec![], + repos: vec![], + }; + } for _ in 0..=5 { let repo = GitRepo { name: "test repo".to_string(), @@ -97,11 +109,12 @@ mod config { url: "https://github.com/cafkafk/gg".to_string(), flags: vec![Clone, Push], }; - config.repos.push(repo); + config.categories[0].repos.push(repo); } let yaml = serde_yaml::to_string(&config).unwrap(); println!("{}", yaml); } + /* #[test] fn read_config_populate() { let _config = Config::new(&RelativePath::new("./src/test/config.yaml").to_string()); @@ -178,6 +191,7 @@ mod config { assert_eq!(config.links[1].tx, "/home/ces/.dots/starship.toml"); } } + */ } /* FIXME Unable to test with networking inside flake diff --git a/src/test/config.yaml b/src/test/config.yaml index 9e96a3b..f555e14 100644 --- a/src/test/config.yaml +++ b/src/test/config.yaml @@ -1,20 +1,26 @@ -repos: - - name: gg - path: /home/ces/.dots/ - url: git@github.com:cafkafk/gg.git - flags: [Clone, Push] - - name: li - path: /home/ces/org/src/git/ - url: git@github.com:cafkafk/li.git - flags: [Clone, Push] - - name: qmk_firmware - path: /home/ces/org/src/git/ - url: git@github.com:cafkafk/qmk_firmware.git - flags: [Clone, Push] - - name: starship - path: /home/ces/org/src/git/ - url: https://github.com/starship/starship.git - flags: [Clone, Push] +categories: + - name: config + flags: [] + repos: + - name: qmk_firmware + path: /home/ces/org/src/git/ + url: git@github.com:cafkafk/qmk_firmware.git + flags: [Clone, Push] + - name: starship + path: /home/ces/org/src/git/ + url: https://github.com/starship/starship.git + flags: [Clone, Push] + - name: utils + flags: [] + repos: + - name: gg + path: /home/ces/.dots/ + url: git@github.com:cafkafk/gg.git + flags: [Clone, Push] + - name: li + path: /home/ces/org/src/git/ + url: git@github.com:cafkafk/li.git + flags: [Clone, Push] links: - name: gg rx: /home/ces/.config/gg