feat(no-emoji): added no-emoji flag

Using atomics! In case we need threading in the future.

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-03 15:34:17 +02:00 committed by Christina Sørensen
parent abddcd98d5
commit 6d39190f69
9 changed files with 76 additions and 26 deletions

View file

@ -2,6 +2,16 @@
All notable changes to this project will be documented in this file.
## [0.1.1] - 2023-07-03
### Bug Fixes
- Fixed help formatting
### Documentation
- Added asciinema demo
## [0.1.0] - 2023-07-03
### Documentation
@ -16,6 +26,10 @@ All notable changes to this project will be documented in this file.
- Made SUCCESS/FAILURE emoji const
- Added flag no-emoji
### Miscellaneous Tasks
- Bump v0.1.0, housekeeping
### Refactor
- Made code more idiomatic

2
Cargo.lock generated
View file

@ -179,7 +179,7 @@ dependencies = [
[[package]]
name = "gg"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"clap",
"clap_mangen",

View file

@ -1,6 +1,6 @@
[package]
name = "gg"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Christina Sørensen"]
repository = "https://github.com/cafkafk/gg"

View file

@ -5,7 +5,7 @@
* 0.1.2
- [ ] Implement Quiet flag
* 0.1.1
- [ ] Implement no-emoji flag
- [X] Implement no-emoji flag
* 0.1.0 [100%] [5/5]
- [X] No functionality regressions
- [X] commit works in quick, fast

View file

@ -25,7 +25,7 @@ use std::os::unix::fs::symlink;
use std::path::Path;
use std::{fs, process::Command};
use crate::utils::strings::{FAILURE_EMOJI, SUCCESS_EMOJI};
use crate::utils::strings::{failure_str, success_str};
/// An enum containing flags that change behaviour of repos and categories
#[derive(PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Debug)]
@ -351,9 +351,9 @@ impl Config {
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_EMOJI, format!("{}: {}", repo.name, op));
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
} else {
sp.stop_and_persist(FAILURE_EMOJI, format!("{}: {}", repo.name, op));
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op));
}
}
}
@ -407,9 +407,9 @@ impl Config {
let op = instruction.operation;
let mut sp = Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op));
if f(repo) {
sp.stop_and_persist(SUCCESS_EMOJI, format!("{}: {}", repo.name, op));
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
} else {
sp.stop_and_persist(FAILURE_EMOJI, format!("{}: {}", repo.name, op));
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op));
break;
}
}
@ -453,9 +453,9 @@ impl Config {
let op = instruction.operation;
let mut sp = Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op));
if f(repo) {
sp.stop_and_persist(SUCCESS_EMOJI, format!("{}: {}", repo.name, op));
sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op));
} else {
sp.stop_and_persist(FAILURE_EMOJI, format!("{}: {}", repo.name, op));
sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op));
}
}
}

View file

@ -39,6 +39,8 @@ mod cli;
#[allow(unused)]
mod git;
#[allow(unused)]
mod settings;
#[allow(unused)]
mod utils;
use cli::{Args, Commands};
@ -50,6 +52,8 @@ use clap::Parser;
#[allow(unused)]
use log::{debug, error, info, trace, warn};
use std::sync::atomic::Ordering;
/// The main loop of the binary
///
/// Here, we handle parsing the configuration file, as well as matching commands
@ -62,7 +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 => todo!(),
args if args.quiet => settings::EMOJIS.store(true, Ordering::Relaxed),
args if args.no_emoji => settings::QUIET.store(true, Ordering::Relaxed),
_ => (),
}
match &mut args.command {

5
src/settings.rs Normal file
View file

@ -0,0 +1,5 @@
use std::sync::atomic::AtomicBool;
pub static QUIET: AtomicBool = AtomicBool::new(false);
pub static EMOJIS: AtomicBool = AtomicBool::new(false);

View file

@ -1,13 +1,6 @@
categories:
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/
@ -15,18 +8,13 @@ categories:
flags:
- Clone
- Push
empty: {}
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
flags:
- Clone
- Push
config:
flags: []
repos:
@ -44,6 +32,18 @@ categories:
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
empty: {}
links:
- name: gg
rx: /home/ces/.config/gg

View file

@ -19,6 +19,10 @@
//! Ideally, at a VERY long term scale, this should be a nice pattern for
//! possible translations.
use std::sync::atomic::Ordering;
use crate::settings;
/// Contains the notice for interactive programs from the GPLv3's "How to Apply
/// These Terms to Your New Programs"
pub const INTERACTIVE_NOTICE: &str = "\
@ -65,3 +69,25 @@ pub const SUCCESS_EMOJI: &str = "✔";
/// Failure emoji
pub const FAILURE_EMOJI: &str = "";
/// Success string
pub const SUCCESS_STRING: &str = "SUCC";
/// Failure string
pub const FAILURE_STRING: &str = "FAIL";
pub fn success_str() -> &'static str {
if settings::EMOJIS.load(Ordering::Relaxed) {
SUCCESS_EMOJI
} else {
SUCCESS_STRING
}
}
pub fn failure_str() -> &'static str {
if settings::EMOJIS.load(Ordering::Relaxed) {
FAILURE_EMOJI
} else {
FAILURE_STRING
}
}