feat!: implemented naive categories
Naive category implementation. Works somewhat, including part of tests. However, I realize now that perhaps, having unique category names in nescesarry for subcommands. On the other hand, allowing them to be non unique would allow splitting up category definitions. But finding the category in a vec would be slow... ...and I want a lot of categories probably... I'm still working on this... here is one way to do it ᕕ( ᐛ )ᕗ Saved in the git log for posterity. Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
bd9c85fb44
commit
3d3b6d6646
3 changed files with 76 additions and 37 deletions
51
src/git.rs
51
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<GitRepo>,
|
||||
pub categories: Vec<Category>,
|
||||
pub links: Vec<Links>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub struct Category {
|
||||
pub name: String,
|
||||
pub flags: Vec<RepoFlags>, // FIXME: not implemented
|
||||
pub repos: Vec<GitRepo>,
|
||||
}
|
||||
|
||||
/// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
22
src/main.rs
22
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue