Skip to content

Commit

Permalink
Use rich to print the text
Browse files Browse the repository at this point in the history
  • Loading branch information
TechNickAI committed Jun 20, 2023
1 parent 327f554 commit a5a25d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cli.py
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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()
Expand All @@ -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__":
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
click
python-dotenv
rich
8 changes: 8 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a5a25d0

Please sign in to comment.