feat(git): started adding multi instruction logic

This follows up on previous commits message, but with a completely
different implementation that is a lot tighter.

It doesn't handle commit messages, but quick is now implemented.

This has also shown that the previous fall-through behaviour of quick
wasn't a bug but a feature, as it would try to pull, not fail if it
couldn't.

This means it would be a good idea to implement an alternative version
of quick that keeps this old behaviour, or probably more likely,
creating a new command that does what the quick in this commit does, and
then finding a way to recreate the old behaviour of quick.

This is dev branch thou, so I don't have to do that before pushing :D

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-01 07:36:00 +02:00
parent 6d83d278e1
commit 3f05ae827a
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
3 changed files with 66 additions and 29 deletions

View file

@ -217,6 +217,11 @@ impl GitRepo {
} }
} }
struct SeriesItem<'series> {
operation: &'series str,
closure: Box<dyn Fn(&GitRepo) -> (bool)>,
}
impl Config { impl Config {
/* GIT RELATED */ /* GIT RELATED */
/// Reads the configuration toml from a path. /// Reads the configuration toml from a path.
@ -278,13 +283,25 @@ impl Config {
/// without blocking the repos that don't have an issue. /// without blocking the repos that don't have an issue.
/// ///
/// This is actually somewhat hairy to do, at least at 6:16 am :S /// This is actually somewhat hairy to do, at least at 6:16 am :S
fn series_on_all<F>(&self, f: F) ///
where /// However, at 6:24, we're so ready! Let's go!
F: Fn(&GitRepo), ///
{ /// Fun fact: only the last element of a tuple must have a dynamically typed size
fn series_on_all(&self, closures: Vec<SeriesItem>) {
for (_, category) in self.categories.iter() { for (_, category) in self.categories.iter() {
for (_, repo) in category.repos.iter() { for (_, repo) in category.repos.iter() {
f(repo); for instruction in closures.iter() {
let f = &instruction.closure;
let op = instruction.operation;
let mut sp =
Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op).into());
if f(repo) {
sp.stop_and_persist("", format!("{}: {}", repo.name, op).into());
} else {
sp.stop_and_persist("", format!("{}: {}", repo.name, op).into());
break;
}
}
} }
} }
} }
@ -317,10 +334,29 @@ impl Config {
/// repositories, skips if fail. /// repositories, skips if fail.
pub fn quick(&self, msg: &String) { pub fn quick(&self, msg: &String) {
debug!("exectuting quick"); debug!("exectuting quick");
self.on_all_spinner("pull", |repo| repo.pull()); let series: Vec<SeriesItem> = vec![
self.on_all_spinner("add", |repo| repo.add_all()); SeriesItem {
self.on_all_spinner("commit", |repo| repo.commit_with_msg(msg)); operation: "pull",
self.on_all_spinner("push", |repo| repo.push()); closure: Box::new(move |repo: &GitRepo| repo.pull()),
},
SeriesItem {
operation: "add",
closure: Box::new(move |repo: &GitRepo| repo.add_all()),
},
SeriesItem {
operation: "commit",
closure: Box::new(move |repo: &GitRepo| repo.commit()),
}, // FIXME doesn't take msg
SeriesItem {
operation: "push",
closure: Box::new(move |repo: &GitRepo| repo.push()),
},
];
self.series_on_all(series);
// self.on_all_spinner("pull", |repo| repo.pull());
// self.on_all_spinner("add", |repo| repo.add_all());
// self.on_all_spinner("commit", |repo| repo.commit_with_msg(msg));
// self.on_all_spinner("push", |repo| repo.push());
} }
/* LINK RELATED */ /* LINK RELATED */

View file

@ -13,6 +13,7 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see https://www.gnu.org/gpl-3.0.html. // along with this program. If not, see https://www.gnu.org/gpl-3.0.html.
#![feature(unsized_tuple_coercion)]
extern crate log; extern crate log;
extern crate pretty_env_logger; extern crate pretty_env_logger;

View file

@ -1,24 +1,14 @@
categories: categories:
utils:
flags: []
repos:
gg:
name: gg
path: /home/ces/.dots/
url: git@github.com:cafkafk/gg.git
flags:
- Clone
- Push
li:
name: li
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/li.git
flags:
- Clone
- Push
config: config:
flags: [] flags: []
repos: repos:
qmk_firmware:
name: qmk_firmware
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/qmk_firmware.git
flags:
- Clone
- Push
starship: starship:
name: starship name: starship
path: /home/ces/org/src/git/ path: /home/ces/org/src/git/
@ -26,10 +16,20 @@ categories:
flags: flags:
- Clone - Clone
- Push - Push
qmk_firmware: utils:
name: qmk_firmware flags: []
repos:
li:
name: li
path: /home/ces/org/src/git/ path: /home/ces/org/src/git/
url: git@github.com:cafkafk/qmk_firmware.git url: git@github.com:cafkafk/li.git
flags:
- Clone
- Push
gg:
name: gg
path: /home/ces/.dots/
url: git@github.com:cafkafk/gg.git
flags: flags:
- Clone - Clone
- Push - Push