From ee8e546b22c620bc3b3f8820be6bcc5bae5a6a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Sun, 2 Jul 2023 11:37:23 +0200 Subject: [PATCH] feat(git): made repo flags optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This finalizes the roadmap item of making certain fields optional. Very nice! Signed-off-by: Christina Sørensen --- Cargo.toml | 2 +- doc/roadmap.org | 4 ++-- src/git.rs | 20 ++++++++++++++++++-- src/main.rs | 2 +- src/test/config.yaml | 11 +++++++++++ src/test/test.yaml | 45 +++++++++++++++++++++++++++----------------- 6 files changed, 61 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4536876..3000428 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "gg" version = "0.0.6" edition = "2021" -authors = ["Christina Sørensen "] +authors = ["Christina Sørensen"] repository = "https://github.com/cafkafk/gg" license = "GPL-3.0-only" diff --git a/doc/roadmap.org b/doc/roadmap.org index eba028b..438ad75 100644 --- a/doc/roadmap.org +++ b/doc/roadmap.org @@ -5,11 +5,11 @@ - [ ] Generic repositories - [ ] Version pinning - [ ] libgit2 (maybe) -* 0.1.0 [40%] [2/5] +* 0.1.0 [60%] [3/5] - [X] No functionality regressions - [X] commit works in quick, fast - [X] commit with edit works - [X] Repo Flags Finished - [ ] Category Flags Finished -- [-] Optional Fields +- [X] Optional Fields - [ ] Subcommands diff --git a/src/git.rs b/src/git.rs index a5c86e2..53e093c 100644 --- a/src/git.rs +++ b/src/git.rs @@ -92,7 +92,8 @@ pub struct GitRepo { pub name: String, pub path: String, pub url: String, - pub flags: Vec, + #[serde(skip_serializing_if = "Option::is_none")] + pub flags: Option>, } //////////////////////////////////// @@ -157,7 +158,12 @@ impl Links { impl GitRepo { /// Clones the repository to its specified folder. fn clone(&self) -> bool { - if self.flags.contains(&RepoFlags::Clone) { + if self + .flags + .as_ref() + .expect("failed to unwrap flags") + .contains(&RepoFlags::Clone) + { // TODO: check if &self.name already exists in dir let output = Command::new("git") .current_dir(&self.path) @@ -176,6 +182,8 @@ impl GitRepo { fn pull(&self) -> bool { if self .flags + .as_ref() + .expect("failed to unwrap flags") .iter() .any(|s| s == &RepoFlags::Pull || s == &RepoFlags::Fast) { @@ -194,6 +202,8 @@ impl GitRepo { fn add_all(&self) -> bool { if self .flags + .as_ref() + .expect("failed to unwrap flags") .iter() .any(|s| s == &RepoFlags::Add || s == &RepoFlags::Quick || s == &RepoFlags::Fast) { @@ -220,6 +230,8 @@ impl GitRepo { fn commit(&self) -> bool { if self .flags + .as_ref() + .expect("failed to unwrap flags") .iter() .any(|s| s == &RepoFlags::Commit || s == &RepoFlags::Quick || s == &RepoFlags::Fast) { @@ -238,6 +250,8 @@ impl GitRepo { fn commit_with_msg(&self, msg: &str) -> bool { if self .flags + .as_ref() + .expect("failed to unwrap flags") .iter() .any(|s| s == &RepoFlags::Commit || s == &RepoFlags::Quick || s == &RepoFlags::Fast) { @@ -258,6 +272,8 @@ impl GitRepo { fn push(&self) -> bool { if self .flags + .as_ref() + .expect("failed to unwrap flags") .iter() .any(|s| s == &RepoFlags::Push || s == &RepoFlags::Quick || s == &RepoFlags::Fast) { diff --git a/src/main.rs b/src/main.rs index c886a5f..6012201 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,7 +150,7 @@ mod config { name: "test repo".to_string(), path: "/tmp".to_string(), url: "https://github.com/cafkafk/gg".to_string(), - flags: vec![Clone, Push], + flags: Some(vec![Clone, Push]), }, ); } diff --git a/src/test/config.yaml b/src/test/config.yaml index dc7960d..54dcaac 100644 --- a/src/test/config.yaml +++ b/src/test/config.yaml @@ -25,6 +25,17 @@ categories: url: git@github.com:cafkafk/li.git flags: [Clone, Push] empty: + stuff: + flags: [] + repos: + gg: + name: gg + path: /home/ces/.dots/ + url: git@github.com:cafkafk/gg.git + li: + name: li + path: /home/ces/org/src/git/ + url: git@github.com:cafkafk/li.git links: - name: gg rx: /home/ces/.config/gg diff --git a/src/test/test.yaml b/src/test/test.yaml index 369371d..b5b3327 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -1,5 +1,31 @@ categories: - empty: {} + utils: + repos: + li: + name: li + path: /home/ces/org/src/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 + stuff: + flags: [] + repos: + li: + name: li + path: /home/ces/org/src/git/ + url: git@github.com:cafkafk/li.git + gg: + name: gg + path: /home/ces/.dots/ + url: git@github.com:cafkafk/gg.git config: flags: [] repos: @@ -17,22 +43,7 @@ categories: flags: - Clone - Push - utils: - repos: - li: - name: li - path: /home/ces/org/src/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 + empty: {} links: - name: gg rx: /home/ces/.config/gg