add more options
All checks were successful
ci/woodpecker/push/build Pipeline was successful

add options for g commit --force & g todo --count
This commit is contained in:
JMARyA 2025-01-27 16:48:43 +01:00
parent 13922afe5e
commit e284913941
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 28 additions and 16 deletions

View file

@ -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"),

View file

@ -144,7 +144,7 @@ pub fn get_languages() -> Vec<String> {
}
/// 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,12 +184,14 @@ pub fn commit(all: bool, done: bool, msg: &str) {
}
}
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
for lang in get_languages() {

View file

@ -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,8 +94,11 @@ pub fn show_todos() {
amount.paint(Color::Red).bold()
}
);
if !count_only {
show_rg(TODO_REGEX);
}
}
}
fn main() {
@ -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();