refactor: remove duplicate code on Config

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-20 16:38:02 +02:00
parent 19a7acf284
commit 8c186b17d3
Signed by: cafkafk
GPG key ID: CDDC792F655251ED

View file

@ -317,46 +317,14 @@ impl Repo {
} }
} }
// pub fn all_on_all(&self, closures: Vec<SeriesItem>, break_on_err: bool) {
macro_rules! run_series { macro_rules! run_series {
($conf:ident, $closures:ident) => { ($conf:ident, $closures:ident) => {
for category in $conf.categories.values() { $conf.all_on_all($closures, false);
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() { };
use RepoKinds::*; ($conf:ident, $closures:ident, $stop_on_err:tt) => {
match &repo.kind { $conf.all_on_all($closures, $stop_on_err);
Some(GitRepo) => {
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);
}
}
}
None => {
println!("unknown kind {:?}", repo.kind)
}
Some(kind) => {
println!("unknown kind {kind:?}")
}
}
}
}
}; };
} }
@ -522,7 +490,7 @@ impl Config {
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op)); sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
} else { } else {
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op)); sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op));
break; break; // NOTE: the difference :D
} }
} else { } else {
f(repo); f(repo);
@ -562,22 +530,44 @@ impl Config {
/// }, /// },
/// ]; /// ];
/// ``` /// ```
pub fn all_on_all(&self, closures: Vec<SeriesItem>) { pub fn all_on_all(&self, closures: Vec<SeriesItem>, break_on_err: bool) {
for category in self.categories.values() { for category in self.categories.values() {
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() { for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
for instruction in &closures { use RepoKinds::*;
let f = &instruction.closure; match &repo.kind {
let op = instruction.operation; Some(GitRepo) => {
if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) { for instruction in &closures {
let mut sp = let f = &instruction.closure;
Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op)); let op = instruction.operation;
if f(repo) { if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) {
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op)); let mut sp = Spinner::new(
} else { Spinners::Dots10,
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op)); 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),
);
if break_on_err {
break;
}
}
} else {
f(repo);
}
} }
} else { }
f(repo); None => {
println!("unknown kind {:?}", repo.kind)
}
Some(kind) => {
println!("unknown kind {kind:?}")
} }
} }
} }