feat: implemented quiet flag

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 <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-03 18:10:13 +02:00 committed by Christina Sørensen
parent b2a0caff02
commit f958739863
5 changed files with 49 additions and 34 deletions

View file

@ -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]

View file

@ -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);
}
}
}

View file

@ -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 {

View file

@ -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

View file

@ -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