From 300549cee3c94453870ba5d589c09080a2ec8083 Mon Sep 17 00:00:00 2001 From: LemonjamesD Date: Mon, 3 Oct 2022 17:13:56 -0400 Subject: [PATCH 1/8] Added Colored --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + 2 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index d0d2dc7..fc90d0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,6 +99,17 @@ dependencies = [ "syn", ] +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + [[package]] name = "commit" version = "0.4.0" @@ -106,6 +117,7 @@ dependencies = [ "anyhow", "assert_fs", "clap", + "colored", "dirs", "inquire", "serde", diff --git a/Cargo.toml b/Cargo.toml index efcb9c9..f13bf39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ serde_json = "1.0.79" clap = { version = "3.1.6", features = ["derive"] } dirs = "4.0.0" anyhow = "1.0.56" +colored = "2.0.0" [dev-dependencies] assert_fs = "1.0.7" From ca38e2a8121964e584e8f6bd289d4632aeae043d Mon Sep 17 00:00:00 2001 From: LemonjamesD Date: Mon, 3 Oct 2022 17:16:04 -0400 Subject: [PATCH 2/8] Added Error if nothing added --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7e36b95..1277b77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,9 @@ mod config; use anyhow::Result; use clap::Parser; use std::io::Write; - +use colored::Colorize; use std::path::PathBuf; +use std::process::{Command, exit}; use commit_message::make_message_commit; @@ -44,6 +45,15 @@ fn main() -> Result<()> { std::env::set_current_dir(current_dir)?; } + if Command::new("git") + .args(["diff", "--cached", "--quiet"]) + .output() + .expect("failed to execute process") + .status.code().is_some() { + eprintln!("{}", "# You have not added anything please do `git add`".red()); + exit(1); + } + let opt = Opt::parse(); if opt.init { let mut file = std::fs::File::create("commit.json")?; From 9b6d153967d7473a243b87594132f937bae2697a Mon Sep 17 00:00:00 2001 From: LemonjamesD Date: Tue, 4 Oct 2022 04:35:31 -0400 Subject: [PATCH 3/8] Checking Error code --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1277b77..0ee2ae2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,15 +45,16 @@ fn main() -> Result<()> { std::env::set_current_dir(current_dir)?; } - if Command::new("git") + if let Some(0) = Command::new("git") .args(["diff", "--cached", "--quiet"]) .output() .expect("failed to execute process") - .status.code().is_some() { + .status.code() { eprintln!("{}", "# You have not added anything please do `git add`".red()); exit(1); } + let opt = Opt::parse(); if opt.init { let mut file = std::fs::File::create("commit.json")?; From 479343772d7878fc5947a84c5138d58ee8eade1f Mon Sep 17 00:00:00 2001 From: LemonjamesD Date: Tue, 4 Oct 2022 04:43:33 -0400 Subject: [PATCH 4/8] Use anyhow error --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0ee2ae2..9ce632f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,11 @@ mod config; use anyhow::Result; use clap::Parser; -use std::io::Write; use colored::Colorize; +use std::io::Write; use std::path::PathBuf; -use std::process::{Command, exit}; +use std::process::{Command}; +use anyhow::anyhow; use commit_message::make_message_commit; @@ -50,8 +51,7 @@ fn main() -> Result<()> { .output() .expect("failed to execute process") .status.code() { - eprintln!("{}", "# You have not added anything please do `git add`".red()); - exit(1); + return Err(anyhow!("{}", "You have not added anything please do `git add`".red())); } From 2d5cb40d747648c780b0b6eb300e4b3b474977da Mon Sep 17 00:00:00 2001 From: LemonjamesD Date: Tue, 4 Oct 2022 14:55:12 -0400 Subject: [PATCH 5/8] formatted --- src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9ce632f..e69e3bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,13 +11,13 @@ mod commit; mod commit_message; mod config; +use anyhow::anyhow; use anyhow::Result; use clap::Parser; use colored::Colorize; use std::io::Write; use std::path::PathBuf; -use std::process::{Command}; -use anyhow::anyhow; +use std::process::Command; use commit_message::make_message_commit; @@ -47,14 +47,18 @@ fn main() -> Result<()> { } if let Some(0) = Command::new("git") - .args(["diff", "--cached", "--quiet"]) - .output() - .expect("failed to execute process") - .status.code() { - return Err(anyhow!("{}", "You have not added anything please do `git add`".red())); + .args(["diff", "--cached", "--quiet"]) + .output() + .expect("failed to execute process") + .status + .code() + { + return Err(anyhow!( + "{}", + "You have not added anything please do `git add`".red() + )); } - let opt = Opt::parse(); if opt.init { let mut file = std::fs::File::create("commit.json")?; From a4f57abb6d82a2674c9342ac6c6fa64b4e76a81e Mon Sep 17 00:00:00 2001 From: Pedro Mendes Date: Thu, 6 Oct 2022 13:27:19 -0300 Subject: [PATCH 6/8] refactor: Dont need to use format --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e69e3bf..eee338a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,6 @@ fn main() -> Result<()> { .code() { return Err(anyhow!( - "{}", "You have not added anything please do `git add`".red() )); } From 44f7af460234200336819889c741c8146bd00674 Mon Sep 17 00:00:00 2001 From: Pedro Mendes Date: Thu, 6 Oct 2022 13:28:57 -0300 Subject: [PATCH 7/8] refactor: Use comparison instead --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index eee338a..a2474a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,12 +46,12 @@ fn main() -> Result<()> { std::env::set_current_dir(current_dir)?; } - if let Some(0) = Command::new("git") + if Command::new("git") .args(["diff", "--cached", "--quiet"]) .output() .expect("failed to execute process") .status - .code() + .code() == Some(0) { return Err(anyhow!( "You have not added anything please do `git add`".red() From c6f3430d813d8210d20914d7cfb5b3e215806479 Mon Sep 17 00:00:00 2001 From: Pedro Mendes Date: Thu, 6 Oct 2022 13:32:56 -0300 Subject: [PATCH 8/8] fix: formatting --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a2474a1..f5466ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,8 @@ fn main() -> Result<()> { .output() .expect("failed to execute process") .status - .code() == Some(0) + .code() + == Some(0) { return Err(anyhow!( "You have not added anything please do `git add`".red()