From 9b4283b9ec791b3901e8f8e6991f6683c7c50873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 3 Jul 2023 12:15:38 +0200 Subject: [PATCH 1/6] doc(readme): added asciinema demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a very basic demo, barely showing anything. Better than nothing still, so here it is. Signed-off-by: Christina Sørensen --- README.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.org b/README.org index 1a922e0..b8a8bcd 100644 --- a/README.org +++ b/README.org @@ -7,6 +7,8 @@ with "dotfiles", and with git support as a first class feature. Configuration is done throug a single yaml file, giving it a paradigm that should bring joy to those that use declarative operating systems and package managers. +#+HTML: + Although this isn't really a case where it matters *that* much for performance, being written in rust instead of e.g. /janky/ scripting languages does also mean it is snappy and reliable, and the /extensive/ (hardly, but eventually) testing -- 2.46.0 From 7dc68e9a3fa65166e6fad604922eacbb1bccd2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 3 Jul 2023 13:28:11 +0200 Subject: [PATCH 2/6] fix: fixed help formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The formatting was kinda broken because I was using multi line strings like I was writing nix :S Signed-off-by: Christina Sørensen --- src/cli.rs | 11 ++++++----- src/utils/strings.rs | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 29d0183..8c9ed78 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -24,13 +24,14 @@ use clap::{ArgAction, CommandFactory, Parser, Subcommand}; const CONFIG_FILE: &str = "/.config/gg/config.yaml"; const HELP_TEMPLATE: &str = "\ - {before-help}{name} {version} - {author-with-newline}{about-with-newline} - {usage-heading} {usage} +{before-help}{name} {version} +{about-with-newline} - {all-args}{after-help} +{usage-heading} {usage} - "; +{all-args}{after-help} + +"; //#[clap(author, version, about, long_about = None)] #[derive(Parser, Debug)] diff --git a/src/utils/strings.rs b/src/utils/strings.rs index 876b80d..e846e99 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -22,11 +22,11 @@ /// Contains the notice for interactive programs from the GPLv3's "How to Apply /// These Terms to Your New Programs" pub const INTERACTIVE_NOTICE: &str = "\ -gg Copyright (C) 2023 Christina Sørensen -This program comes with ABSOLUTELY NO WARRANTY; for details type `gg --warranty'. -This is free software, and you are welcome to redistribute it -under certain conditions; type `gg --license' for details. -"; +gg Copyright (C) 2023 Christina Sørensen + +This program comes with ABSOLUTELY NO WARRANTY; for details type `gg +--warranty'. This is free software, and you are welcome to redistribute it under +certain conditions; type `gg --license' for details. "; /// Contains the license part of the long notice for interactive programs from /// the GPLv3's "How to Apply These Terms to Your New Programs" -- 2.46.0 From b154ca080fb65652dd6981884e5cb2e1d1651950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 3 Jul 2023 15:34:17 +0200 Subject: [PATCH 3/6] feat(no-emoji): added no-emoji flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using atomics! In case we need threading in the future. Signed-off-by: Christina Sørensen --- CHANGELOG.md | 14 ++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- doc/roadmap.org | 2 +- src/git.rs | 14 +++++++------- src/main.rs | 7 ++++++- src/settings.rs | 5 +++++ src/test/test.yaml | 30 +++++++++++++++--------------- src/utils/strings.rs | 26 ++++++++++++++++++++++++++ 9 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 src/settings.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index b4b2176..b8fac8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Cargo.lock b/Cargo.lock index 6dd9650..cf305b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,7 +179,7 @@ dependencies = [ [[package]] name = "gg" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "clap_mangen", diff --git a/Cargo.toml b/Cargo.toml index 10a1fc3..07818f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/doc/roadmap.org b/doc/roadmap.org index 8ebeb22..836f61c 100644 --- a/doc/roadmap.org +++ b/doc/roadmap.org @@ -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 diff --git a/src/git.rs b/src/git.rs index e495b4e..c3ea72c 100644 --- a/src/git.rs +++ b/src/git.rs @@ -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)); } } } diff --git a/src/main.rs b/src/main.rs index d97985b..00c15b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { diff --git a/src/settings.rs b/src/settings.rs new file mode 100644 index 0000000..fda53d7 --- /dev/null +++ b/src/settings.rs @@ -0,0 +1,5 @@ +use std::sync::atomic::AtomicBool; + +pub static QUIET: AtomicBool = AtomicBool::new(false); + +pub static EMOJIS: AtomicBool = AtomicBool::new(false); diff --git a/src/test/test.yaml b/src/test/test.yaml index e433730..ddd15f2 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -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 diff --git a/src/utils/strings.rs b/src/utils/strings.rs index e846e99..23c1413 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -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 + } +} -- 2.46.0 From 868498bb038666b98075536d22cf8bd3f093c22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 3 Jul 2023 15:36:15 +0200 Subject: [PATCH 4/6] chore(version): bump to v0.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8fac8b..fd4bd71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,14 @@ All notable changes to this project will be documented in this file. - Added asciinema demo +### Features + +- Added no-emoji flag + +### Miscellaneous Tasks + +- Bump to v0.1.1 + ## [0.1.0] - 2023-07-03 ### Documentation -- 2.46.0 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 5/6] 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 -- 2.46.0 From 73b73150f8696a73ea8edc89ef67072badad08fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 3 Jul 2023 18:19:48 +0200 Subject: [PATCH 6/6] chore(version): bump to v0.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- CHANGELOG.md | 6 ++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4bd71..ed1bc9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [0.1.2] - 2023-07-03 + +### Features + +- Implemented quiet flag + ## [0.1.1] - 2023-07-03 ### Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index cf305b4..9415f31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,7 +179,7 @@ dependencies = [ [[package]] name = "gg" -version = "0.1.1" +version = "0.1.2" dependencies = [ "clap", "clap_mangen", diff --git a/Cargo.toml b/Cargo.toml index 07818f5..2af5769 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gg" -version = "0.1.1" +version = "0.1.2" edition = "2021" authors = ["Christina Sørensen"] repository = "https://github.com/cafkafk/gg" diff --git a/src/main.rs b/src/main.rs index b1ad43a..1503283 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ fn main() { 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::QUIET.store(true, Ordering::Relaxed), - args if args.no_emoji => settings::EMOJI.store(true, Ordering::Relaxed), + args if args.no_emoji => settings::EMOJIS.store(true, Ordering::Relaxed), _ => (), } match &mut args.command { -- 2.46.0