Refactored agent command handling to remove redundant boiler-plate code. Commands are parsed dynamically based on a single definition. Command-specific actions might still need distinct implementations.

This commit is contained in:
Jakob Friedl
2025-07-14 22:14:27 +02:00
parent 2d2c94ed38
commit b8b276d887
5 changed files with 240 additions and 129 deletions

View File

@@ -60,16 +60,16 @@ var parser = newParser:
command("exit"):
nohelpflag()
proc handleConsoleCommand*(cq: Conquest, args: varargs[string]) =
proc handleConsoleCommand*(cq: Conquest, args: string) =
# Return if no command (or just whitespace) is entered
if args[0].replace(" ", "").len == 0: return
if args.replace(" ", "").len == 0: return
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
cq.writeLine(fgBlue, styleBright, fmt"[{date}] ", resetStyle, styleBright, args[0])
cq.writeLine(fgBlue, styleBright, fmt"[{date}] ", resetStyle, styleBright, args)
try:
let opts = parser.parse(args[0].split(" ").filterIt(it.len > 0))
let opts = parser.parse(args.split(" ").filterIt(it.len > 0))
case opts.command