Files
overcode/commands/cmd_run.py

54 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
Run Command - Execute OverCode files
"""
import os
import sys
import subprocess
from colorama import Fore, Style, init
# Add parent directory to path to import interpreter
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from over_interpreter import OverCodeInterpreter
init(autoreset=True)
class RunCommand:
"""Execute OverCode files"""
def __init__(self, cwd, filename):
self.cwd = cwd
self.filename = filename.strip()
def run(self):
"""Execute the run command"""
if not self.filename:
print(Fore.RED + "❌ Please specify a file to run")
print(Fore.YELLOW + "Usage: run filename.ovc")
return
# Add .ovc extension if not present
if not self.filename.endswith('.ovc'):
self.filename += '.ovc'
filepath = os.path.join(self.cwd, self.filename)
if not os.path.exists(filepath):
print(Fore.RED + f"❌ File not found: {self.filename}")
return
try:
# Use the OverCode interpreter
interpreter = OverCodeInterpreter()
with open(filepath, 'r', encoding='utf-8') as f:
source_code = f.read()
print(Fore.MAGENTA + f"🚀 Executing: {self.filename}")
print(Fore.CYAN + "=" * 50)
interpreter.interpret(source_code, verbose=True)
except Exception as e:
print(Fore.RED + f"❌ Error executing file: {e}")