-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
38 lines (30 loc) Β· 1.44 KB
/
Copy pathcli.py
File metadata and controls
38 lines (30 loc) Β· 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from agent import generate_code
import os
from rich.prompt import Prompt
from rich.console import Console
from git_utils import commit_and_push
console = Console()
def main():
while True:
task = Prompt.ask("\nπ€ What do you want the AI to code?")
if task.lower() in ["exit", "quit"]:
console.print("Exiting the program. Goodbye! π", style="bold red")
break
code, explanation = generate_code(task)
file_name = Prompt.ask("\nπΎ What do you want to name the file? (without extension)")
file_extension = Prompt.ask("\nπ What is the file extension? (e.g., .py, .js, .java)")
file_path = f"{file_name}{file_extension}"
with open(file_path, "w") as file:
file.write(code)
readme_path = "README.md"
with open(readme_path, "a", encoding="utf-8") as readme:
readme.write(f"\n\n## π Task: {task}\n\n")
readme.write(f"### π§ Explanation\n{explanation}\n")
readme.write(f"\n### π Code File: `{file_path}`\n")
console.print(f"\nβ
Code generated and saved to {file_path}!", style="bold green")
console.print("\nπ» Generated Code:\n", style="bold blue")
console.print(code, style="bold white")
commit = Prompt.ask("π Enter commit message")
commit_and_push(commit, repo_path=os.getcwd())
if __name__ == "__main__":
main()