refactor: started work on generic macro

This is to help make series operations more generic.

This refactor has been needed for a while, and I'm very excited to
finally start working on it, but this is just the bare minimum, we
still need to handle on a repo type basis.

But also, yes, this starts the slow crawl towards generic repos intead
of hardcoded functions for each repo type (links, gitrepo) etc

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-17 10:45:13 +02:00
parent 5cc54e23f5
commit 579d9ea972
Signed by: cafkafk
GPG key ID: CDDC792F655251ED

View file

@ -304,6 +304,30 @@ impl GitRepo {
} }
} }
macro_rules! run_series {
($conf:ident, $closures:ident) => {
for category in $conf.categories.values() {
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
for instruction in &$closures {
let f = &instruction.closure;
let op = instruction.operation;
if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) {
let mut sp =
Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op));
if f(repo) {
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
} else {
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op));
}
} else {
f(repo);
}
}
}
}
};
}
impl Config { impl Config {
/// Loads the configuration toml from a path in to the Config struct. /// Loads the configuration toml from a path in to the Config struct.
pub fn new(path: &String) -> Self { pub fn new(path: &String) -> Self {
@ -602,7 +626,8 @@ impl Config {
closure: Box::new(GitRepo::push), closure: Box::new(GitRepo::push),
}, },
]; ];
self.all_on_all(series); //self.all_on_all(series);
run_series!(self, series);
} }
/// 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.