chore: merge 0.0.6 #6
3 changed files with 52 additions and 30 deletions
27
src/git.rs
27
src/git.rs
|
@ -16,6 +16,7 @@
|
|||
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::canonicalize;
|
||||
use std::os::unix::fs::symlink;
|
||||
use std::path::Path;
|
||||
|
@ -33,15 +34,20 @@ pub enum RepoFlags {
|
|||
/// Represents the config.toml file.
|
||||
#[derive(PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub categories: Vec<Category>,
|
||||
/// map of all categories
|
||||
///
|
||||
/// Key should conceptually be seen as the name of the category.
|
||||
pub categories: HashMap<String, 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>,
|
||||
/// map of all categories
|
||||
///
|
||||
/// Key should conceptually be seen as the name of the category.
|
||||
pub repos: HashMap<String, GitRepo>,
|
||||
}
|
||||
|
||||
/// Contain fields for a single link.
|
||||
|
@ -211,12 +217,15 @@ impl Config {
|
|||
})
|
||||
}
|
||||
/// Runs associated function on all repos in config
|
||||
///
|
||||
/// TODO: need to be made over a generic repo type
|
||||
fn on_all<F>(&self, f: F)
|
||||
where
|
||||
F: Fn(&GitRepo),
|
||||
{
|
||||
for category in self.categories.iter() {
|
||||
for repo in category.repos.iter() {
|
||||
for (_, category) in self.categories.iter() {
|
||||
println!("{category:?}");
|
||||
for (_, repo) in category.repos.iter() {
|
||||
f(repo);
|
||||
}
|
||||
}
|
||||
|
@ -224,11 +233,9 @@ impl Config {
|
|||
/// Tries to pull all repositories, skips if fail.
|
||||
pub fn pull_all(&self) {
|
||||
debug!("exectuting pull_all");
|
||||
for category in self.categories.iter() {
|
||||
for repo in category.repos.iter() {
|
||||
repo.pull();
|
||||
}
|
||||
}
|
||||
self.on_all(|repo| {
|
||||
repo.pull();
|
||||
});
|
||||
}
|
||||
/// Tries to clone all repositories, skips if fail.
|
||||
pub fn clone_all(&self) {
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -74,42 +74,57 @@ mod config {
|
|||
use git::RepoFlags::{Clone, Push};
|
||||
use git::{Category, GitRepo};
|
||||
use relative_path::RelativePath;
|
||||
use std::collections::HashMap;
|
||||
use std::env::current_dir;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
#[test]
|
||||
fn init_config() {
|
||||
let _config = Config {
|
||||
categories: vec![],
|
||||
categories: HashMap::new(),
|
||||
links: vec![],
|
||||
};
|
||||
}
|
||||
#[test]
|
||||
fn init_config_populate() {
|
||||
let defaultCategory = Category {
|
||||
name: "Default".to_string(),
|
||||
flags: vec![],
|
||||
repos: vec![],
|
||||
repos: HashMap::new(),
|
||||
};
|
||||
let mut config = Config {
|
||||
categories: vec![defaultCategory],
|
||||
categories: HashMap::new(),
|
||||
links: vec![],
|
||||
};
|
||||
for _ in 0..=5 {
|
||||
let category = Category {
|
||||
name: "ehh".to_string(),
|
||||
flags: vec![],
|
||||
repos: vec![],
|
||||
repos: HashMap::new(),
|
||||
};
|
||||
}
|
||||
for _ in 0..=5 {
|
||||
let repo = GitRepo {
|
||||
name: "test repo".to_string(),
|
||||
path: "/tmp".to_string(),
|
||||
url: "https://github.com/cafkafk/gg".to_string(),
|
||||
flags: vec![Clone, Push],
|
||||
};
|
||||
config.categories[0].repos.push(repo);
|
||||
config
|
||||
.categories
|
||||
.insert(format!("{}", 0).to_string(), defaultCategory);
|
||||
for i in 0..=5 {
|
||||
config
|
||||
.categories
|
||||
.get_mut(&format!("{}", 0).to_string())
|
||||
.expect("category not found")
|
||||
.repos
|
||||
.insert(
|
||||
format!("{}", i).to_string(),
|
||||
GitRepo {
|
||||
name: "test repo".to_string(),
|
||||
path: "/tmp".to_string(),
|
||||
url: "https://github.com/cafkafk/gg".to_string(),
|
||||
flags: vec![Clone, Push],
|
||||
},
|
||||
);
|
||||
// let repo = GitRepo {
|
||||
// name: "test repo".to_string(),
|
||||
// path: "/tmp".to_string(),
|
||||
// url: "https://github.com/cafkafk/gg".to_string(),
|
||||
// flags: vec![Clone, Push],
|
||||
// };
|
||||
}
|
||||
let yaml = serde_yaml::to_string(&config).unwrap();
|
||||
println!("{}", yaml);
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
categories:
|
||||
- name: config
|
||||
config:
|
||||
flags: []
|
||||
repos:
|
||||
- name: qmk_firmware
|
||||
qmk_firmware:
|
||||
path: /home/ces/org/src/git/
|
||||
url: git@github.com:cafkafk/qmk_firmware.git
|
||||
flags: [Clone, Push]
|
||||
- name: starship
|
||||
starship:
|
||||
path: /home/ces/org/src/git/
|
||||
url: https://github.com/starship/starship.git
|
||||
flags: [Clone, Push]
|
||||
- name: utils
|
||||
utils:
|
||||
flags: []
|
||||
repos:
|
||||
- name: gg
|
||||
gg:
|
||||
path: /home/ces/.dots/
|
||||
url: git@github.com:cafkafk/gg.git
|
||||
flags: [Clone, Push]
|
||||
- name: li
|
||||
li:
|
||||
path: /home/ces/org/src/git/
|
||||
url: git@github.com:cafkafk/li.git
|
||||
flags: [Clone, Push]
|
||||
|
|
Loading…
Reference in a new issue