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(
|
.subcommand(
|
||||||
command!("todo")
|
command!("todo")
|
||||||
.about("Show open TODOs in repository")
|
.about("Show open TODOs in repository")
|
||||||
.alias("t"),
|
.alias("t")
|
||||||
|
.arg(arg!(-c --count "Only show TODO count")),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
command!("new")
|
command!("new")
|
||||||
|
@ -25,8 +26,12 @@ pub fn get_args() -> clap::ArgMatches {
|
||||||
command!("commit")
|
command!("commit")
|
||||||
.about("Commit current changes")
|
.about("Commit current changes")
|
||||||
.alias("c")
|
.alias("c")
|
||||||
|
.arg(arg!(-f --force "Force commit and skip any checks"))
|
||||||
.arg(arg!(-a --all "Add all changed files to commit"))
|
.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(
|
||||||
arg!(-i --interactive "Write interactive commit message with gitmoji standard")
|
arg!(-i --interactive "Write interactive commit message with gitmoji standard")
|
||||||
.conflicts_with("message"),
|
.conflicts_with("message"),
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub fn get_languages() -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Commit changes to the repository.
|
/// 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
|
// Work In Progress Save Commit
|
||||||
if last_commit().as_str() == "WIP" {
|
if last_commit().as_str() == "WIP" {
|
||||||
// Get files affected by commit
|
// Get files affected by commit
|
||||||
|
@ -184,12 +184,14 @@ pub fn commit(all: bool, done: bool, msg: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !forced {
|
||||||
// Impossible commits
|
// Impossible commits
|
||||||
if no_commit_amount() > 0 {
|
if no_commit_amount() > 0 {
|
||||||
println!("{}", "Unable to commit because of:".paint(Color::Red));
|
println!("{}", "Unable to commit because of:".paint(Color::Red));
|
||||||
show_rg(NO_COMMIT_REGEX);
|
show_rg(NO_COMMIT_REGEX);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Laguage specific pre-commit hooks
|
// Laguage specific pre-commit hooks
|
||||||
for lang in get_languages() {
|
for lang in get_languages() {
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -16,7 +16,7 @@ pub fn read_stdout(e: Exec) -> String {
|
||||||
str.trim().to_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: )";
|
const NO_COMMIT_REGEX: &str = r"(NOCOMMIT|ENSURE: )";
|
||||||
|
|
||||||
pub fn no_commit_amount() -> u64 {
|
pub fn no_commit_amount() -> u64 {
|
||||||
|
@ -71,7 +71,7 @@ pub fn show_rg(regex: &str) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_todos() {
|
pub fn show_todos(count_only: bool) {
|
||||||
let amount = todos_amount();
|
let amount = todos_amount();
|
||||||
if amount == 0 {
|
if amount == 0 {
|
||||||
println!("{}", "✨ No TODOs 🍃".paint(Color::Green).bold());
|
println!("{}", "✨ No TODOs 🍃".paint(Color::Green).bold());
|
||||||
|
@ -94,8 +94,11 @@ pub fn show_todos() {
|
||||||
amount.paint(Color::Red).bold()
|
amount.paint(Color::Red).bold()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if !count_only {
|
||||||
show_rg(TODO_REGEX);
|
show_rg(TODO_REGEX);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -130,6 +133,7 @@ fn main() {
|
||||||
Some(("commit", commit_args)) => {
|
Some(("commit", commit_args)) => {
|
||||||
let all = commit_args.get_flag("all");
|
let all = commit_args.get_flag("all");
|
||||||
let done = commit_args.get_flag("done");
|
let done = commit_args.get_flag("done");
|
||||||
|
let forced = commit_args.get_flag("force");
|
||||||
let msg: Option<&String> = commit_args.get_one("message");
|
let msg: Option<&String> = commit_args.get_one("message");
|
||||||
let interactive = commit_args.get_flag("interactive");
|
let interactive = commit_args.get_flag("interactive");
|
||||||
|
|
||||||
|
@ -140,13 +144,13 @@ fn main() {
|
||||||
.with_page_size(5)
|
.with_page_size(5)
|
||||||
.prompt();
|
.prompt();
|
||||||
let msg = CommitMessage::new(gitmoji, title, body.ok()).to_msg();
|
let msg = CommitMessage::new(gitmoji, title, body.ok()).to_msg();
|
||||||
commit(all, done, &msg);
|
commit(all, done, forced, &msg);
|
||||||
} else {
|
} else {
|
||||||
commit(all, done, msg.unwrap());
|
commit(all, done, forced, msg.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(("save", _)) => {
|
Some(("save", _)) => {
|
||||||
commit(true, false, "WIP");
|
commit(true, false, true, "WIP");
|
||||||
}
|
}
|
||||||
Some(("fetch", _)) => {
|
Some(("fetch", _)) => {
|
||||||
fetch();
|
fetch();
|
||||||
|
@ -154,8 +158,9 @@ fn main() {
|
||||||
Some(("pull", _)) => {
|
Some(("pull", _)) => {
|
||||||
pull();
|
pull();
|
||||||
}
|
}
|
||||||
Some(("todo", _)) => {
|
Some(("todo", todo_arg)) => {
|
||||||
show_todos();
|
let count = todo_arg.get_flag("count");
|
||||||
|
show_todos(count);
|
||||||
}
|
}
|
||||||
Some(("log", _)) => {
|
Some(("log", _)) => {
|
||||||
Exec::cmd("serie").popen().unwrap().wait().unwrap();
|
Exec::cmd("serie").popen().unwrap().wait().unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue