From a8d4d013786916a48ec91c470b5974914f91e8e3 Mon Sep 17 00:00:00 2001 From: neru Date: Tue, 13 May 2025 00:32:10 -0300 Subject: [PATCH] feat: add command descriptions and help cmd --- lua/CC Tweaked/tutel/tutel-host.lua | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lua/CC Tweaked/tutel/tutel-host.lua b/lua/CC Tweaked/tutel/tutel-host.lua index 48813fa..791440f 100644 --- a/lua/CC Tweaked/tutel/tutel-host.lua +++ b/lua/CC Tweaked/tutel/tutel-host.lua @@ -267,8 +267,13 @@ registerEventListener("key", scrollLogs) local consoleCommands = {} local commandBuffer = "" -function registerConsoleCommand(name, handler) - consoleCommands[name] = handler +function registerConsoleCommand(name, handler, desc) + local cmd = { + ["name"] = name, + ["handler"] = handler, + ["desc"] = desc or "" + } + consoleCommands[name] = cmd end function processCommand() @@ -285,7 +290,7 @@ function processCommand() if consoleCommands[cmd] then log.info("> %s %s", cmd, table.concat(args, " ")) - consoleCommands[cmd](args) + consoleCommands[cmd].handler(args) else log.warning("Unknown command: %s", cmd) end @@ -319,26 +324,26 @@ function echoCommand(args) log.info(table.concat(args, " ")) end -registerConsoleCommand("echo", echoCommand) +registerConsoleCommand("echo", echoCommand, "Prints your message") function exitCommand(args) shouldRun = false end -registerConsoleCommand("exit", exitCommand) +registerConsoleCommand("exit", exitCommand, "Exits the program") function scanCommand(args) log.info("broadcasting SCAN") sendToAll("SCAN", { ["hostChannel"] = HOST_CHANNEL }) end -registerConsoleCommand("scan", scanCommand) +registerConsoleCommand("scan", scanCommand, "Sends out a scan command to pair unlinked turtles") function clearCommand() log.buffer = {} end -registerConsoleCommand("clear", clearCommand) +registerConsoleCommand("clear", clearCommand, "Clears the console") function turtlesCommand() if #turtles == 0 then @@ -357,7 +362,15 @@ function turtlesCommand() end end -registerConsoleCommand("turtles", turtlesCommand) +registerConsoleCommand("turtles", turtlesCommand, "Lists all the linked turtles") + +function helpCommand() + log.info("----- commands -----") + for _, cmd in pairs(consoleCommands) do + log.info("%s - %s", cmd.name, cmd.desc) + end +end +registerConsoleCommand("help", helpCommand, "Prints out all the console commands") --[[ drawing functions