Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit 6492ad6

Browse files
committed
feat(refactor): Add a verbose flag for seeing git commands
1 parent 5e3c680 commit 6492ad6

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

.dod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# --- Optional Issue Tracker Integration ---
1515
# If true, the check-commit tool will require the --issue <ID> flag
1616
# to be used with the commit command, ensuring all work is traceable.
17-
issue_reference_required: true
17+
issue_reference_required: false
1818

1919
checklist:
2020
# --- Code Quality & Testing (High-Impact Checks) ---

src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use clap::Parser;
77
pub struct Cli {
88
#[command(subcommand)]
99
pub command: Commands,
10+
#[arg(long)]
11+
pub verbose: bool,
1012
}
1113

1214
#[derive(clap::Subcommand, Debug)]

src/git.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::process::{Command, Stdio};
22
use thiserror::Error;
33
use anyhow::{Context, Result};
4+
use colored::Colorize;
45

56
// Using `thiserror` to create a structured error type.
67
#[derive(Error, Debug)]
@@ -10,8 +11,10 @@ pub enum GitError {
1011
}
1112

1213
/// Runs a Git command with the specified subcommand and arguments.
13-
fn run_git_command(command: &str, args: &[&str]) -> Result<String> {
14-
println!("[RUNNING] git {} {}", command, args.join(" "));
14+
fn run_git_command(command: &str, args: &[&str], verbose: bool) -> Result<String> {
15+
if verbose {
16+
println!("{} git {} {}", "[RUNNING] ".green(), command, args.join(" "));
17+
}
1518
let output = Command::new("git")
1619
.arg(command)
1720
.args(args)
@@ -28,27 +31,27 @@ fn run_git_command(command: &str, args: &[&str]) -> Result<String> {
2831
}
2932

3033
/// Show the current status of the repository.
31-
pub fn status() -> Result<String> {
32-
run_git_command("status", &["--short"])
34+
pub fn status(verbose: bool) -> Result<String> {
35+
run_git_command("status", &["--short"], verbose)
3336
}
3437

3538
/// Pull the latest changes with rebase.
36-
pub fn pull_latest_with_rebase() -> Result<String> {
39+
pub fn pull_latest_with_rebase(verbose: bool) -> Result<String> {
3740
// Using --autostash to safely handle local changes before pulling.
38-
run_git_command("pull", &["--rebase", "--autostash"])
41+
run_git_command("pull", &["--rebase", "--autostash"], verbose)
3942
}
4043

4144
/// Add all changes to the staging area.
42-
pub fn add_all() -> Result<String> {
43-
run_git_command("add", &["."])
45+
pub fn add_all(verbose: bool) -> Result<String> {
46+
run_git_command("add", &["."], verbose)
4447
}
4548

4649
/// Commit changes with a message.
47-
pub fn commit(message: &str) -> Result<String> {
48-
run_git_command("commit", &["-m", message])
50+
pub fn commit(message: &str, verbose: bool) -> Result<String> {
51+
run_git_command("commit", &["-m", message], verbose)
4952
}
5053

5154
/// Push changes to the remote repository.
52-
pub fn push() -> Result<String> {
53-
run_git_command("push", &[])
55+
pub fn push(verbose: bool) -> Result<String> {
56+
run_git_command("push", &[], verbose)
5457
}

src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn handle_interactive_commit(
8484
/// Main function that parses command line arguments and executes the appropriate git operations.
8585
fn main() -> anyhow::Result<()> {
8686
let cli = cli::Cli::parse();
87+
let verbose = cli.verbose;
8788
let config = read_dod_config()?;
8889
if config.checklist.is_empty() {
8990
println!("{}", "No checklist items defined.".yellow());
@@ -92,7 +93,7 @@ fn main() -> anyhow::Result<()> {
9293
match cli.command {
9394
cli::Commands::Status => {
9495
println!("--- Checking Git status ---");
95-
let status = git::status()?;
96+
let status = git::status(verbose)?;
9697
println!("{}", format!("Git Status:\n{}", status).green());
9798
}
9899
cli::Commands::Commit { r#type, scope, message, no_verify, issue} => {
@@ -112,10 +113,10 @@ fn main() -> anyhow::Result<()> {
112113

113114
if let Some(commit_message) = final_commit_message {
114115
println!("{}", format!("Commit message will be:\n---\n{}\n---", commit_message).blue());
115-
git::add_all()?;
116-
git::pull_latest_with_rebase()?;
117-
git::commit(&commit_message)?;
118-
git::push()?;
116+
git::add_all(verbose)?;
117+
git::pull_latest_with_rebase(verbose)?;
118+
git::commit(&commit_message, verbose)?;
119+
git::push(verbose)?;
119120
println!("{}", "Successfully committed and pushed changes.".green());
120121
}
121122
}

0 commit comments

Comments
 (0)