Rework module system. Now modules/commands are defined in a single file each, with both the function executed by teh agent and the definition for server-side argument parsing.

This commit is contained in:
Jakob Friedl
2025-07-25 16:41:29 +02:00
parent ad31b90687
commit 7bf135750c
25 changed files with 549 additions and 489 deletions

38
src/modules/manager.nim Normal file
View File

@@ -0,0 +1,38 @@
import tables, strformat
import ../common/[types, utils]
# Import modules
import
shell,
sleep,
filesystem
type
ModuleManager* = object
commandsByType*: Table[CommandType, Command]
commandsByName*: Table[string, Command]
var manager: ModuleManager
proc registerCommands(commands: seq[Command]) {.discardable.} =
for cmd in commands:
manager.commandsByType[cmd.commandType] = cmd
manager.commandsByName[cmd.name] = cmd
proc loadModules*() =
# Register all imported commands
registerCommands(shell.commands)
registerCommands(sleep.commands)
registerCommands(filesystem.commands)
proc getCommandByType*(cmdType: CommandType): Command =
return manager.commandsByType[cmdType]
proc getCommandByName*(cmdName: string): Command =
try:
return manager.commandsByName[cmdName]
except ValueError:
raise newException(ValueError, fmt"The command '{cmdName}' does not exist.")
proc getAvailableCommands*(): Table[string, Command] =
return manager.commandsByName