diff --git a/src/git.rs b/src/git.rs index 594ab53..7db9a4d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -217,6 +217,11 @@ impl GitRepo { } } +struct SeriesItem<'series> { + operation: &'series str, + closure: Box (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(&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) { 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 = 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 */ diff --git a/src/main.rs b/src/main.rs index fc55b28..2da0ea7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/test/test.yaml b/src/test/test.yaml index 4284adc..b8dd2eb 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -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