11use std:: process:: { Command , Stdio } ;
22use thiserror:: Error ;
33use 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}
0 commit comments