feat(git): made categories.repo optional
This is nice because it sets us up for the future, when we eventually implement link categories, so we can share categories for both repos, links, neither or either. Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
a000d37b72
commit
1c6793f8e4
4 changed files with 29 additions and 22 deletions
11
src/git.rs
11
src/git.rs
|
@ -73,7 +73,8 @@ pub struct Category {
|
|||
/// map of all categories
|
||||
///
|
||||
/// Key should conceptually be seen as the name of the category.
|
||||
pub repos: HashMap<String, GitRepo>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repos: Option<HashMap<String, GitRepo>>,
|
||||
}
|
||||
|
||||
/// Contain fields for a single link.
|
||||
|
@ -311,7 +312,7 @@ impl Config {
|
|||
F: Fn(&GitRepo),
|
||||
{
|
||||
for (_, category) in self.categories.iter() {
|
||||
for (_, repo) in category.repos.iter() {
|
||||
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||
f(repo);
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +327,7 @@ impl Config {
|
|||
F: Fn(&GitRepo) -> bool,
|
||||
{
|
||||
for (_, category) in self.categories.iter() {
|
||||
for (_, repo) in category.repos.iter() {
|
||||
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||
let mut sp =
|
||||
Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op).into());
|
||||
if f(repo) {
|
||||
|
@ -380,7 +381,7 @@ impl Config {
|
|||
/// ```
|
||||
pub fn series_on_all(&self, closures: Vec<SeriesItem>) {
|
||||
for (_, category) in self.categories.iter() {
|
||||
for (_, repo) in category.repos.iter() {
|
||||
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||
for instruction in closures.iter() {
|
||||
let f = &instruction.closure;
|
||||
let op = instruction.operation;
|
||||
|
@ -427,7 +428,7 @@ impl Config {
|
|||
/// ```
|
||||
pub fn all_on_all(&self, closures: Vec<SeriesItem>) {
|
||||
for (_, category) in self.categories.iter() {
|
||||
for (_, repo) in category.repos.iter() {
|
||||
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||
for instruction in closures.iter() {
|
||||
let f = &instruction.closure;
|
||||
let op = instruction.operation;
|
||||
|
|
|
@ -127,7 +127,7 @@ mod config {
|
|||
fn init_config_populate() {
|
||||
let default_category = Category {
|
||||
flags: Some(vec![]),
|
||||
repos: HashMap::new(),
|
||||
repos: Some(HashMap::new()),
|
||||
};
|
||||
let mut config = Config {
|
||||
categories: HashMap::new(),
|
||||
|
@ -142,6 +142,8 @@ mod config {
|
|||
.get_mut(&format!("{}", 0).to_string())
|
||||
.expect("category not found")
|
||||
.repos
|
||||
.as_mut()
|
||||
.expect("failed to get repo")
|
||||
.insert(
|
||||
format!("{}", i).to_string(),
|
||||
GitRepo {
|
||||
|
@ -196,6 +198,8 @@ mod config {
|
|||
.get(cat_name)
|
||||
.expect("failed to get category")
|
||||
.repos
|
||||
.as_ref()
|
||||
.expect("failed to get repo")
|
||||
.get(repo_name)
|
||||
.expect("failed to get category"))
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ categories:
|
|||
path: /home/ces/org/src/git/
|
||||
url: git@github.com:cafkafk/li.git
|
||||
flags: [Clone, Push]
|
||||
empty:
|
||||
links:
|
||||
- name: gg
|
||||
rx: /home/ces/.config/gg
|
||||
|
|
|
@ -1,20 +1,5 @@
|
|||
categories:
|
||||
utils:
|
||||
repos:
|
||||
gg:
|
||||
name: gg
|
||||
path: /home/ces/.dots/
|
||||
url: git@github.com:cafkafk/gg.git
|
||||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
li:
|
||||
name: li
|
||||
path: /home/ces/org/src/git/
|
||||
url: git@github.com:cafkafk/li.git
|
||||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
empty: {}
|
||||
config:
|
||||
flags: []
|
||||
repos:
|
||||
|
@ -32,6 +17,22 @@ categories:
|
|||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
utils:
|
||||
repos:
|
||||
li:
|
||||
name: li
|
||||
path: /home/ces/org/src/git/
|
||||
url: git@github.com:cafkafk/li.git
|
||||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
gg:
|
||||
name: gg
|
||||
path: /home/ces/.dots/
|
||||
url: git@github.com:cafkafk/gg.git
|
||||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
links:
|
||||
- name: gg
|
||||
rx: /home/ces/.config/gg
|
||||
|
|
Loading…
Reference in a new issue