refactor: remove duplicate code on Config
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
6993753889
commit
72533ea8e8
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 {
|
||||
($conf:ident, $closures:ident) => {
|
||||
for category in $conf.categories.values() {
|
||||
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||
use RepoKinds::*;
|
||||
match &repo.kind {
|
||||
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:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$conf.all_on_all($closures, false);
|
||||
};
|
||||
($conf:ident, $closures:ident, $stop_on_err:tt) => {
|
||||
$conf.all_on_all($closures, $stop_on_err);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -522,7 +490,7 @@ impl Config {
|
|||
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
|
||||
} else {
|
||||
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op));
|
||||
break;
|
||||
break; // NOTE: the difference :D
|
||||
}
|
||||
} else {
|
||||
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 (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||
use RepoKinds::*;
|
||||
match &repo.kind {
|
||||
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));
|
||||
let mut sp = Spinner::new(
|
||||
Spinners::Dots10,
|
||||
format!("{}: {}", repo.name, op),
|
||||
);
|
||||
if f(repo) {
|
||||
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
|
||||
sp.stop_and_persist(
|
||||
success_str(),
|
||||
format!("{}: {}", repo.name, op),
|
||||
);
|
||||
} 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 {
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue