diff --git a/cli.py b/cli.py index f782b6f..958465e 100644 --- a/cli.py +++ b/cli.py @@ -1,7 +1,11 @@ from dotenv import find_dotenv, load_dotenv from pathlib import Path +from rich.console import Console from setup import __version__ -import click, os, webbrowser +import click, os, sys, webbrowser + +# Create a Console object +console = Console() # Load environment variables from .env file load_dotenv(find_dotenv()) @@ -13,7 +17,10 @@ def setup_environment(): openai_api_key_url = "https://platform.openai.com/account/api-keys" - click.echo("The OPENAI_API_KEY environment variable is not set. Let's fix that for you by creating a .env file.") + console.print( + "[bold red]The OPENAI_API_KEY environment variable is not set.[/bold red]\n" + "Let's fix that for you by creating a .env file." + ) if click.confirm("Do you want me to open the OpenAI API keys page for you in a browser?"): webbrowser.open(openai_api_key_url) @@ -29,11 +36,14 @@ def setup_environment(): else: env.write(line) - click.echo("Created .env file with your OpenAI API key. You're all set!") + console.print("[bold green]Created .env file with your OpenAI API key. You're all set![/bold green]") return True - raise click.UsageError("Please set an API key in the OPENAI_API_KEY environment variable or in a .env file.") + console.print( + "[bold red]Please set an API key in the OPENAI_API_KEY environment variable or in a .env file.[/bold red]" + ) + sys.exit(1) return False @@ -48,7 +58,7 @@ def cli(): @cli.command() def version(): """Print the version number.""" - click.echo(f"AICodeBot version {__version__}") + console.print(f"[bold cyan]AICodeBot version {__version__}[/bold cyan]") @cli.command() @@ -58,7 +68,7 @@ def joke(verbose): setup_environment() api_key = os.getenv("OPENAI_API_KEY") if verbose: - click.echo(f"Using API key: {api_key}") + console.print(f"[bold yellow]Using API key: {api_key}[/bold yellow]") if __name__ == "__main__": diff --git a/requirements/requirements.in b/requirements/requirements.in index 9bfa0d2..8607df7 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -1,2 +1,3 @@ click python-dotenv +rich diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 455e35f..14511b6 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -6,5 +6,13 @@ # click==8.1.3 # via -r requirements.in +markdown-it-py==3.0.0 + # via rich +mdurl==0.1.2 + # via markdown-it-py +pygments==2.15.1 + # via rich python-dotenv==1.0.0 # via -r requirements.in +rich==13.4.2 + # via -r requirements.in