fix(git): made categories with only links possible

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-05 14:07:44 +02:00
parent 8a9e9e52b1
commit e0038dd6f7
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
2 changed files with 63 additions and 20 deletions

View file

@ -342,25 +342,57 @@ impl Config {
} }
} }
} }
// /// Runs associated function on all repos in config
// fn on_all_spinner<F>(&self, op: &str, f: F)
// where
// F: Fn(&GitRepo) -> bool,
// {
// for category in self.categories.values() {
// for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
// 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);
// }
// }
// }
// }
/// Runs associated function on all repos in config /// Runs associated function on all repos in config
fn on_all_spinner<F>(&self, op: &str, f: F) fn on_all_repos_spinner<F>(&self, op: &str, f: F)
where where
F: Fn(&GitRepo) -> bool, F: Fn(&GitRepo) -> 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() { match category.repos.as_ref() {
Some(repos) => {
for repo in repos.values() {
if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) { 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) { 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),
);
} }
} else { } else {
f(repo); f(repo);
} }
} }
} }
None => continue,
};
}
} }
/// Runs associated function on all links in config /// Runs associated function on all links in config
fn on_all_links_spinner<F>(&self, op: &str, f: F) fn on_all_links_spinner<F>(&self, op: &str, f: F)
@ -541,27 +573,27 @@ impl Config {
/// Tries to pull all repositories, skips if fail. /// Tries to pull all repositories, skips if fail.
pub fn pull_all(&self) { pub fn pull_all(&self) {
debug!("exectuting pull_all"); debug!("exectuting pull_all");
self.on_all_spinner("pull", GitRepo::pull); self.on_all_repos_spinner("pull", GitRepo::pull);
} }
/// Tries to clone all repositories, skips if fail. /// Tries to clone all repossitories, skips if fail.
pub fn clone_all(&self) { pub fn clone_all(&self) {
debug!("exectuting clone_all"); debug!("exectuting clone_all");
self.on_all_spinner("clone", GitRepo::clone); self.on_all_repos_spinner("clone", GitRepo::clone);
} }
/// Tries to add all work in all repositories, skips if fail. /// Tries to add all work in all repossitories, skips if fail.
pub fn add_all(&self) { pub fn add_all(&self) {
debug!("exectuting clone_all"); debug!("exectuting clone_all");
self.on_all_spinner("add", GitRepo::add_all); self.on_all_repos_spinner("add", GitRepo::add_all);
} }
/// Tries to commit all repositories one at a time, skips if fail. /// Tries to commit all repossitories one at a time, skips if fail.
pub fn commit_all(&self) { pub fn commit_all(&self) {
debug!("exectuting clone_all"); debug!("exectuting clone_all");
self.on_all_spinner("commit", GitRepo::commit); self.on_all_repos_spinner("commit", GitRepo::commit);
} }
/// Tries to commit all repositories with msg, skips if fail. /// Tries to commit all repossitories with msg, skips if fail.
pub fn commit_all_msg(&self, msg: &str) { pub fn commit_all_msg(&self, msg: &str) {
debug!("exectuting clone_all"); debug!("exectuting clone_all");
self.on_all_spinner("commit", |repo| repo.commit_with_msg(msg)); self.on_all_repos_spinner("commit", |repo| repo.commit_with_msg(msg));
} }
/// 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.

View file

@ -45,3 +45,14 @@ categories:
name: starship name: starship
rx: /home/ces/.config/starship.toml rx: /home/ces/.config/starship.toml
tx: /home/ces/.dots/starship.toml tx: /home/ces/.dots/starship.toml
fluff:
flags: []
links:
gg:
name: gg
rx: /home/ces/.config/gg
tx: /home/ces/.dots/gg
starship:
name: starship
rx: /home/ces/.config/starship.toml
tx: /home/ces/.dots/starship.toml