add options for g commit --force & g todo --count
This commit is contained in:
parent
13922afe5e
commit
e284913941
3 changed files with 28 additions and 16 deletions
|
@ -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"),
|
||||
|
|
14
src/git.rs
14
src/git.rs
|
@ -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,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
|
||||
|
|
21
src/main.rs
21
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();
|
||||
|
|
Loading…
Add table
Reference in a new issue