From e284913941367e7032476f4bf777b51ddd32c743 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 27 Jan 2025 16:48:43 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20more=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add options for g commit --force & g todo --count --- src/args.rs | 9 +++++++-- src/git.rs | 14 ++++++++------ src/main.rs | 21 +++++++++++++-------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/args.rs b/src/args.rs index 365db17..679a201 100644 --- a/src/args.rs +++ b/src/args.rs @@ -13,7 +13,8 @@ pub fn get_args() -> clap::ArgMatches { .subcommand( command!("todo") .about("Show open TODOs in repository") - .alias("t"), + .alias("t") + .arg(arg!(-c --count "Only show TODO count")), ) .subcommand( command!("new") @@ -25,8 +26,12 @@ pub fn get_args() -> clap::ArgMatches { command!("commit") .about("Commit current changes") .alias("c") + .arg(arg!(-f --force "Force commit and skip any checks")) .arg(arg!(-a --all "Add all changed files to commit")) - .arg(arg!(-d --done "Only allow commiting if no TODOs are present")) + .arg( + arg!(-d --done "Only allow commiting if no TODOs are present") + .conflicts_with("force"), + ) .arg( arg!(-i --interactive "Write interactive commit message with gitmoji standard") .conflicts_with("message"), diff --git a/src/git.rs b/src/git.rs index c261286..1bbb80e 100644 --- a/src/git.rs +++ b/src/git.rs @@ -144,7 +144,7 @@ pub fn get_languages() -> Vec { } /// Commit changes to the repository. -pub fn commit(all: bool, done: bool, msg: &str) { +pub fn commit(all: bool, done: bool, forced: bool, msg: &str) { // Work In Progress Save Commit if last_commit().as_str() == "WIP" { // Get files affected by commit @@ -184,11 +184,13 @@ pub fn commit(all: bool, done: bool, msg: &str) { } } - // Impossible commits - if no_commit_amount() > 0 { - println!("{}", "Unable to commit because of:".paint(Color::Red)); - show_rg(NO_COMMIT_REGEX); - std::process::exit(1); + if !forced { + // Impossible commits + if no_commit_amount() > 0 { + println!("{}", "Unable to commit because of:".paint(Color::Red)); + show_rg(NO_COMMIT_REGEX); + std::process::exit(1); + } } // Laguage specific pre-commit hooks diff --git a/src/main.rs b/src/main.rs index 894583d..1ea1414 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ pub fn read_stdout(e: Exec) -> String { str.trim().to_string() } -const TODO_REGEX: &str = r" (todo|unimplemented|refactor|wip|fix)(:|!|\n|\ :)"; +const TODO_REGEX: &str = r"( |#)(todo|unimplemented|refactor|wip|fix)(:|!|\n| :)"; const NO_COMMIT_REGEX: &str = r"(NOCOMMIT|ENSURE: )"; pub fn no_commit_amount() -> u64 { @@ -71,7 +71,7 @@ pub fn show_rg(regex: &str) { .unwrap(); } -pub fn show_todos() { +pub fn show_todos(count_only: bool) { let amount = todos_amount(); if amount == 0 { println!("{}", "✨ No TODOs 🍃".paint(Color::Green).bold()); @@ -94,7 +94,10 @@ pub fn show_todos() { amount.paint(Color::Red).bold() } ); - show_rg(TODO_REGEX); + + if !count_only { + show_rg(TODO_REGEX); + } } } @@ -130,6 +133,7 @@ fn main() { Some(("commit", commit_args)) => { let all = commit_args.get_flag("all"); let done = commit_args.get_flag("done"); + let forced = commit_args.get_flag("force"); let msg: Option<&String> = commit_args.get_one("message"); let interactive = commit_args.get_flag("interactive"); @@ -140,13 +144,13 @@ fn main() { .with_page_size(5) .prompt(); let msg = CommitMessage::new(gitmoji, title, body.ok()).to_msg(); - commit(all, done, &msg); + commit(all, done, forced, &msg); } else { - commit(all, done, msg.unwrap()); + commit(all, done, forced, msg.unwrap()); } } Some(("save", _)) => { - commit(true, false, "WIP"); + commit(true, false, true, "WIP"); } Some(("fetch", _)) => { fetch(); @@ -154,8 +158,9 @@ fn main() { Some(("pull", _)) => { pull(); } - Some(("todo", _)) => { - show_todos(); + Some(("todo", todo_arg)) => { + let count = todo_arg.get_flag("count"); + show_todos(count); } Some(("log", _)) => { Exec::cmd("serie").popen().unwrap().wait().unwrap();