from agicli.printplus import pr, inp
import os
from agicli.welcome import get_detail
def current_year():
from datetime import datetime
return datetime.now().year
def create_project(path="agicli/projects/"):
"""Creates a new project directory and initializes a README file."""
os.makedirs(path, exist_ok=True)
project_name = inp("Enter the project name: ", color="red", margin=1).strip()
while not project_name.isidentifier():
pr("Invalid project name. Please use only letters, numbers, and underscores, and do not start with a number.", color="yellow")
project_name = inp("Enter the project name: ", color="red", margin=1).strip()
project_path = os.path.join(path, project_name)
os.makedirs(project_path, exist_ok=True)
readme_path = os.path.join(project_path, "README.md")
with open(readme_path, 'w') as f:
f.write(f"# {project_name}\n\nWelcome to {project_name}! \n\n# AUTHOR \nThis project was created by {get_detail('user_name')}.\n\n# LICENSE \n\n See the [LICENSE](LICENSE) file for license information.\n")
license = inp("Choose a license 'mit', 'none', 'agicli': ", color="red", margin=1).strip().lower()
if license == "mit":
license_text = f"""
MIT License
Copyright (c) {current_year()} {get_detail("user_name")}
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
elif license == "agicli":
license_text = f"""
AG Corp's AGI CLI License
Copyright (c) {current_year()} {get_detail("user_name")}
All rights reserved. This project is licensed under AG Corp's AGI CLI License. Unauthorized copying of this file, via any medium is strictly prohibited.
"""
else:
license_text = "No license specified. Ask the author for permission to use."
license_path = os.path.join(project_path, "LICENSE")
with open(license_path, 'w') as f:
f.write(license_text)
initialize_prefab = inp("Initialize with prefab structure? ('python', 'website', 'bf'/'b', 'b++' or 'none'): ", color="red", margin=1).strip().lower()
if initialize_prefab == "python":
# make main.py file in the project directory
main_path = os.path.join(project_path, "main.py")
with open(main_path, 'w') as f:
f.write(f"# {project_name}")
elif initialize_prefab == "website":
# create index.html, styles.css, script.js files in the project directory
index_path = os.path.join(project_path, "index.html")
with open(index_path, 'w') as f:
f.write(f"\n\n
\n {project_name}\n \n\n\n
Welcome to {project_name}!
\n \n\n")
styles_path = os.path.join(project_path, "styles.css")
with open(styles_path, 'w') as f:
f.write("body { font-family: Arial, sans-serif; }")
script_path = os.path.join(project_path, "script.js")
with open(script_path, 'w') as f:
f.write(f"console.log('Welcome to {project_name}!');")
elif initialize_prefab in ["bf", "b"]:
# create a hello world brainfuck file (.b)
bf_path = os.path.join(project_path, "main.b")
with open(bf_path, 'w') as f:
code = """
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++.---.+++++++..+++.
-------------------------------------------------------------
------------------.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++.
>++++++++++.
"""
f.write(code)
elif initialize_prefab == "b++":
pr("Initializing B++ project. B++ is a custom sdk for brainfuck development.", color="yellow")
# create a hello world B++ file (.bpp)
bpp_path = os.path.join(project_path, "main.bpp")
with open(bpp_path, 'w') as f:
code = """
// main.bpp
print("B++ Supports print statements!")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++.---.+++++++..+++.
-------------------------------------------------------------
------------------.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++.
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++.
>++++++++++.
"""
f.write(code)
interpreter_path = os.path.join(project_path, "interpreter.py")
with open(interpreter_path, 'w') as f:
code = """
# Simple B++ Interpreter
import re
def bpp_interpreter(code):
# Handle print statements first
print_pattern = r'print\\s*\\(\\s*"([^"]*)"\\s*\\)'
for match in re.finditer(print_pattern, code):
print(match.group(1))
# Remove print statements and comments from code for brainfuck execution
code = re.sub(print_pattern, '', code)
code = re.sub(r'//.*', '', code) # Remove single-line comments
# Filter to only brainfuck commands
code = ''.join(filter(lambda x: x in ['+', '-', '<', '>', '.', ',', '[', ']'], code))
tape = [0] * 30000
pointer = 0
pc = 0
loop_stack = []
while pc < len(code):
cmd = code[pc]
if cmd == '+':
tape[pointer] = (tape[pointer] + 1) % 256
elif cmd == '-':
tape[pointer] = (tape[pointer] - 1) % 256
elif cmd == '>':
pointer += 1
elif cmd == '<':
pointer -= 1
elif cmd == '.':
print(chr(tape[pointer]), end='')
elif cmd == ',':
tape[pointer] = ord(input()[0]) % 256
elif cmd == '[':
if tape[pointer] == 0:
open_brackets = 1
while open_brackets > 0:
pc += 1
if code[pc] == '[':
open_brackets += 1
elif code[pc] == ']':
open_brackets -= 1
else:
loop_stack.append(pc)
elif cmd == ']':
if tape[pointer] != 0:
pc = loop_stack[-1]
else:
loop_stack.pop()
pc += 1
if __name__ == "__main__":
with open("main.bpp", "r") as f:
bpp_interpreter(f.read())
"""
f.write(code)
elif initialize_prefab == "none":
pr("No prefab structure initialized.", color="yellow")
else:
pr("Unknown prefab option. No prefab structure initialized.", color="yellow")
pr(f"Project '{project_name}' created successfully at {project_path}", color="red")