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:
parent
6d83d278e1
commit
3f05ae827a
3 changed files with 66 additions and 29 deletions
54
src/git.rs
54
src/git.rs
|
@ -217,6 +217,11 @@ impl GitRepo {
|
|||
}
|
||||
}
|
||||
|
||||
struct SeriesItem<'series> {
|
||||
operation: &'series str,
|
||||
closure: Box<dyn Fn(&GitRepo) -> (bool)>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/* GIT RELATED */
|
||||
/// Reads the configuration toml from a path.
|
||||
|
@ -278,13 +283,25 @@ impl Config {
|
|||
/// without blocking the repos that don't have an issue.
|
||||
///
|
||||
/// This is actually somewhat hairy to do, at least at 6:16 am :S
|
||||
fn series_on_all<F>(&self, f: F)
|
||||
where
|
||||
F: Fn(&GitRepo),
|
||||
{
|
||||
///
|
||||
/// However, at 6:24, we're so ready! Let's go!
|
||||
///
|
||||
/// 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 (_, 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.
|
||||
pub fn quick(&self, msg: &String) {
|
||||
debug!("exectuting quick");
|
||||
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());
|
||||
let series: Vec<SeriesItem> = vec![
|
||||
SeriesItem {
|
||||
operation: "pull",
|
||||
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 */
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//
|
||||
// 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.
|
||||
#![feature(unsized_tuple_coercion)]
|
||||
|
||||
extern crate log;
|
||||
extern crate pretty_env_logger;
|
||||
|
|
|
@ -1,24 +1,14 @@
|
|||
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:
|
||||
flags: []
|
||||
repos:
|
||||
qmk_firmware:
|
||||
name: qmk_firmware
|
||||
path: /home/ces/org/src/git/
|
||||
url: git@github.com:cafkafk/qmk_firmware.git
|
||||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
starship:
|
||||
name: starship
|
||||
path: /home/ces/org/src/git/
|
||||
|
@ -26,10 +16,20 @@ categories:
|
|||
flags:
|
||||
- Clone
|
||||
- Push
|
||||
qmk_firmware:
|
||||
name: qmk_firmware
|
||||
utils:
|
||||
flags: []
|
||||
repos:
|
||||
li:
|
||||
name: li
|
||||
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:
|
||||
- Clone
|
||||
- Push
|
||||
|
|
Loading…
Reference in a new issue