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