diff --git a/src/git.rs b/src/git.rs index 620a658..a5c86e2 100644 --- a/src/git.rs +++ b/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, + #[serde(skip_serializing_if = "Option::is_none")] + pub repos: Option>, } /// 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) { 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) { 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; diff --git a/src/main.rs b/src/main.rs index 087e4fe..c886a5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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")) } diff --git a/src/test/config.yaml b/src/test/config.yaml index 91aa884..dc7960d 100644 --- a/src/test/config.yaml +++ b/src/test/config.yaml @@ -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 diff --git a/src/test/test.yaml b/src/test/test.yaml index 89fb77d..369371d 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -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