Set up ability to run commands from the terminal

This commit is contained in:
Andrew Miner
2025-10-06 20:57:46 -06:00
parent a8b6e6b15e
commit 4637137152
18 changed files with 231 additions and 49 deletions
+28
View File
@@ -0,0 +1,28 @@
from tungston.core.world import World
import inspect
import sys
# Class ############################################################################################
class Runner:
def __init__(self, world:World):
self.world = world
def abort(self, message:str, status:int=-1):
print(message)
sys.exit(status)
def run(self, argv:list[str]):
if len(sys.argv) < 2:
abort("Please provide a command name")
commandName = "_command_" + argv[1]
for name, doCommand in inspect.getmembers(self):
if name == commandName:
doCommand(*argv[2:])
sys.exit(0)
abort("No command named: " + argv[1])