1212import typer
1313from dotenv import load_dotenv
1414from pydantic import BaseModel , Field
15- from rich .console import Console
1615
1716from gcop import prompt , version
1817from gcop .config import ModelConfig , get_config
1918from gcop .utils import check_version_update , migrate_config_if_needed
19+ from gcop .utils .logger import Color , logger
2020
2121load_dotenv ()
2222
2525 help = "gcop is your local git command copilot" ,
2626 add_completion = False ,
2727)
28- console = Console ()
2928
3029
3130class CommitMessage (BaseModel ):
@@ -99,7 +98,7 @@ def check_version_before_command(f: Callable) -> Callable:
9998
10099 @wraps (f )
101100 def wrapper (* args , ** kwargs ):
102- check_version_update (console )
101+ check_version_update ()
103102 return f (* args , ** kwargs )
104103
105104 return wrapper
@@ -199,10 +198,10 @@ def init_command():
199198 check = True ,
200199 encoding = "utf-8" ,
201200 )
202- console . print ( "[green] git aliases added successfully[/]" )
201+ logger . color_info ( " git aliases added successfully" , color = Color . GREEN )
203202
204203 config_command (from_init = True )
205- console . print ( "[green] gcop initialized successfully[/]" )
204+ logger . color_info ( " gcop initialized successfully" , color = Color . GREEN )
206205 except subprocess .CalledProcessError as error :
207206 print (f"Error adding git aliases: { error } " )
208207
@@ -409,28 +408,28 @@ def info_command():
409408 shell = True ,
410409 ).strip ()
411410
412- console . print (f"[bold] Project Name:[/] { project_name } " )
413- console . print (f"[bold] Current Branch:[/] { current_branch } " )
414- console . print (f"[bold] Latest Commit:[/] { latest_commit } " )
415- console . print (f"[bold] Uncommitted Changes:[/] { uncommitted_changes } " )
416- console . print (f"[bold] Remote URL:[/] { remote_url } " )
417- console . print (f"[bold] Total Commits:[/] { total_commits } " )
418- console . print (f"[bold] Contributors:[/] { contributors } " )
419- console . print (f"[bold] Repository Created:[/] { creation_time } " )
420- console . print (f"[bold] Last Modified:[/] { last_modified } " )
421- console . print (f"[bold] Repository Size:[/] { repo_size } " )
422- console . print (f"[bold] Most Active Contributor:[/] { most_active } " )
423- console . print (f"[bold] Most Changed File:[/] { most_changed } " )
424- console . print (f"[bold] Line Count by Language:[/] \n { line_count } " )
425- console . print (f"[bold] Latest Tag:[/] { latest_tag } " )
426- console . print (f"[bold] Branch Count:[/] { branch_count } " )
427- console . print (f"[bold] Untracked Files:[/] { untracked_count } " )
428- console . print (f"[bold] Submodules:[/] { submodules } " )
429- console . print (f"[bold] Latest Merge Commit:[/] { latest_merge } " )
430- console . print (f"[bold] File Type Statistics:[/] \n { file_types } " )
411+ logger . color_info (f"Project Name: { project_name } " )
412+ logger . color_info (f"Current Branch: { current_branch } " )
413+ logger . color_info (f"Latest Commit: { latest_commit } " )
414+ logger . color_info (f"Uncommitted Changes: { uncommitted_changes } " )
415+ logger . color_info (f"Remote URL: { remote_url } " )
416+ logger . color_info (f"Total Commits: { total_commits } " )
417+ logger . color_info (f"Contributors: { contributors } " )
418+ logger . color_info (f"Repository Created: { creation_time } " )
419+ logger . color_info (f"Last Modified: { last_modified } " )
420+ logger . color_info (f"Repository Size: { repo_size } " )
421+ logger . color_info (f"Most Active Contributor: { most_active } " )
422+ logger . color_info (f"Most Changed File: { most_changed } " )
423+ logger . color_info (f"Line Count by Language:\n { line_count } " )
424+ logger . color_info (f"Latest Tag: { latest_tag } " )
425+ logger . color_info (f"Branch Count: { branch_count } " )
426+ logger . color_info (f"Untracked Files: { untracked_count } " )
427+ logger . color_info (f"Submodules: { submodules } " )
428+ logger . color_info (f"Latest Merge Commit: { latest_merge } " )
429+ logger . color_info (f"File Type Statistics:\n { file_types } " )
431430
432431 except subprocess .CalledProcessError as e :
433- console . print (f"[red] Error getting repository information: { e } [/]" )
432+ logger . color_info (f"Error getting repository information: { e } " , color = Color . RED )
434433
435434
436435@app .command (name = "commit" )
@@ -455,18 +454,20 @@ def commit_command(
455454 diff : str = get_git_diff ("--staged" )
456455
457456 if not diff :
458- console . print ( "[yellow] No staged changes[/]" )
457+ logger . color_info ( " No staged changes" , color = Color . YELLOW )
459458 return
460459
461- console . print (f"[yellow][ Code diff] \n { diff } [/]" )
462- console . print ("[bold][ On Ready] Generating commit message... [/] " )
460+ logger . color_info (f"[Code diff] \n { diff } " , color = Color . YELLOW )
461+ logger . color_info ("[On Ready] Generating commit message..." )
463462
464463 commit_messages : CommitMessage = generate_commit_message (
465464 diff , instruction , previous_commit_message
466465 )
467466
468- console .print (f"[bold][Thought] { commit_messages .thought } [/]" )
469- console .print (f"[green][Generated commit message]\n { commit_messages .content } [/]" )
467+ logger .color_info (f"[Thought] { commit_messages .thought } " )
468+ logger .color_info (
469+ f"[Generated commit message]\n { commit_messages .content } " , color = Color .GREEN
470+ )
470471
471472 actions : Dict [str , Callable ] = {
472473 "yes" : lambda : subprocess .run (["git" , "commit" , "-m" , commit_messages .content ]),
@@ -477,7 +478,9 @@ def commit_command(
477478 instruction = questionary .text ("Please enter your feedback:" ).ask (),
478479 previous_commit_message = commit_messages .content ,
479480 ),
480- "exit" : lambda : console .print ("[yellow]Exiting commit process.[/]" ),
481+ "exit" : lambda : logger .color_info (
482+ "Exiting commit process." , color = Color .YELLOW
483+ ),
481484 }
482485
483486 response = questionary .select (
@@ -492,14 +495,14 @@ def commit_command(
492495@check_version_before_command
493496def help_command ():
494497 """Show help message"""
495- help_message = """
496- [bold] gcop[/] is your local git command copilot
497- [bold] Version: [/] {version}
498- [bold] GitHub: https://github.com/Undertone0809/gcop[/]
498+ help_message = f """
499+ gcop is your local git command copilot
500+ Version: { version }
501+ GitHub: https://github.com/Undertone0809/gcop
499502
500- [bold] Usage: gcop [OPTIONS] COMMAND[/]
503+ Usage: gcop [OPTIONS] COMMAND
501504
502- [bold] Commands:
505+ Commands:
503506 git p Push the changes to the remote repository
504507 git pf Push the changes to the remote repository with force
505508 git undo Undo the last commit but keep the file changes
@@ -514,7 +517,7 @@ def help_command():
514517 git info Display basic information about the current git repository
515518""" # noqa
516519
517- console . print (help_message )
520+ logger . color_info (help_message )
518521
519522
520523if __name__ == "__main__" :
0 commit comments