From 038ddd94b6460582aa42a8bece1797ad694bb294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 3 Jul 2023 18:10:13 +0200 Subject: [PATCH] feat: implemented quiet flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This took a fair amount of fiddeling with attempts at a more elegant solution before I just accepted that it wasn't gonna be that fancy and went with what is in this commit. Signed-off-by: Christina Sørensen --- doc/roadmap.org | 2 +- src/git.rs | 41 ++++++++++++++++++++++++++++------------- src/main.rs | 4 ++-- src/test/test.yaml | 32 ++++++++++++++++---------------- src/utils/strings.rs | 4 ++-- 5 files changed, 49 insertions(+), 34 deletions(-) diff --git a/doc/roadmap.org b/doc/roadmap.org index 836f61c..194466f 100644 --- a/doc/roadmap.org +++ b/doc/roadmap.org @@ -3,7 +3,7 @@ * 0.2.0 (maybe) - [ ] Links in categories? * 0.1.2 -- [ ] Implement Quiet flag +- [X] Implement Quiet flag * 0.1.1 - [X] Implement no-emoji flag * 0.1.0 [100%] [5/5] diff --git a/src/git.rs b/src/git.rs index c3ea72c..8734bc3 100644 --- a/src/git.rs +++ b/src/git.rs @@ -25,6 +25,7 @@ use std::os::unix::fs::symlink; use std::path::Path; use std::{fs, process::Command}; +use crate::settings; use crate::utils::strings::{failure_str, success_str}; /// An enum containing flags that change behaviour of repos and categories @@ -349,11 +350,15 @@ impl Config { { for category in self.categories.values() { for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() { - let mut sp = Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op)); - if f(repo) { - sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op)); + 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 { - sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op)); + f(repo); } } } @@ -405,12 +410,17 @@ impl Config { for instruction in &closures { let f = &instruction.closure; let op = instruction.operation; - let mut sp = Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op)); - if f(repo) { - sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op)); + 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)); + break; + } } else { - sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op)); - break; + f(repo); } } } @@ -451,11 +461,16 @@ impl Config { for instruction in &closures { let f = &instruction.closure; let op = instruction.operation; - let mut sp = Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op)); - if f(repo) { - sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op)); + 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 { - sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op)); + f(repo); } } } diff --git a/src/main.rs b/src/main.rs index 00c15b9..b1ad43a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,8 +66,8 @@ fn main() { args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE), args if args.warranty => println!("{}", utils::strings::INTERACTIVE_WARRANTY), args if args.code_of_conduct => println!("{}", utils::strings::INTERACTIVE_COC), - args if args.quiet => settings::EMOJIS.store(true, Ordering::Relaxed), - args if args.no_emoji => settings::QUIET.store(true, Ordering::Relaxed), + args if args.quiet => settings::QUIET.store(true, Ordering::Relaxed), + args if args.no_emoji => settings::EMOJI.store(true, Ordering::Relaxed), _ => (), } match &mut args.command { diff --git a/src/test/test.yaml b/src/test/test.yaml index ddd15f2..56c844b 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -1,20 +1,4 @@ categories: - utils: - 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: @@ -43,6 +27,22 @@ categories: name: gg path: /home/ces/.dots/ url: git@github.com:cafkafk/gg.git + utils: + 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 empty: {} links: - name: gg diff --git a/src/utils/strings.rs b/src/utils/strings.rs index 23c1413..b11eebc 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -77,7 +77,7 @@ pub const SUCCESS_STRING: &str = "SUCC"; pub const FAILURE_STRING: &str = "FAIL"; pub fn success_str() -> &'static str { - if settings::EMOJIS.load(Ordering::Relaxed) { + if !settings::EMOJIS.load(Ordering::Relaxed) { SUCCESS_EMOJI } else { SUCCESS_STRING @@ -85,7 +85,7 @@ pub fn success_str() -> &'static str { } pub fn failure_str() -> &'static str { - if settings::EMOJIS.load(Ordering::Relaxed) { + if !settings::EMOJIS.load(Ordering::Relaxed) { FAILURE_EMOJI } else { FAILURE_STRING