refactor: remove duplicate code on Config
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
19a7acf284
commit
8c186b17d3
1 changed files with 42 additions and 52 deletions
78
src/git.rs
78
src/git.rs
|
@ -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,25 +530,47 @@ 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() {
|
||||||
|
use RepoKinds::*;
|
||||||
|
match &repo.kind {
|
||||||
|
Some(GitRepo) => {
|
||||||
for instruction in &closures {
|
for instruction in &closures {
|
||||||
let f = &instruction.closure;
|
let f = &instruction.closure;
|
||||||
let op = instruction.operation;
|
let op = instruction.operation;
|
||||||
if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) {
|
if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) {
|
||||||
let mut sp =
|
let mut sp = Spinner::new(
|
||||||
Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op));
|
Spinners::Dots10,
|
||||||
|
format!("{}: {}", repo.name, op),
|
||||||
|
);
|
||||||
if f(repo) {
|
if f(repo) {
|
||||||
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),
|
||||||
|
);
|
||||||
|
if break_on_err {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f(repo);
|
f(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
println!("unknown kind {:?}", repo.kind)
|
||||||
|
}
|
||||||
|
Some(kind) => {
|
||||||
|
println!("unknown kind {kind:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_repo<F>(&self, cat_name: &str, repo_name: &str, f: F)
|
pub fn get_repo<F>(&self, cat_name: &str, repo_name: &str, f: F)
|
||||||
|
|
Loading…
Reference in a new issue