feat: add command descriptions and help cmd

This commit is contained in:
2025-05-13 00:32:10 -03:00
parent e47713e0c3
commit a8d4d01378
+21 -8
View File
@@ -267,8 +267,13 @@ registerEventListener("key", scrollLogs)
local consoleCommands = {} local consoleCommands = {}
local commandBuffer = "" local commandBuffer = ""
function registerConsoleCommand(name, handler) function registerConsoleCommand(name, handler, desc)
consoleCommands[name] = handler local cmd = {
["name"] = name,
["handler"] = handler,
["desc"] = desc or ""
}
consoleCommands[name] = cmd
end end
function processCommand() function processCommand()
@@ -285,7 +290,7 @@ function processCommand()
if consoleCommands[cmd] then if consoleCommands[cmd] then
log.info("> %s %s", cmd, table.concat(args, " ")) log.info("> %s %s", cmd, table.concat(args, " "))
consoleCommands[cmd](args) consoleCommands[cmd].handler(args)
else else
log.warning("Unknown command: %s", cmd) log.warning("Unknown command: %s", cmd)
end end
@@ -319,26 +324,26 @@ function echoCommand(args)
log.info(table.concat(args, " ")) log.info(table.concat(args, " "))
end end
registerConsoleCommand("echo", echoCommand) registerConsoleCommand("echo", echoCommand, "Prints your message")
function exitCommand(args) function exitCommand(args)
shouldRun = false shouldRun = false
end end
registerConsoleCommand("exit", exitCommand) registerConsoleCommand("exit", exitCommand, "Exits the program")
function scanCommand(args) function scanCommand(args)
log.info("broadcasting SCAN") log.info("broadcasting SCAN")
sendToAll("SCAN", { ["hostChannel"] = HOST_CHANNEL }) sendToAll("SCAN", { ["hostChannel"] = HOST_CHANNEL })
end end
registerConsoleCommand("scan", scanCommand) registerConsoleCommand("scan", scanCommand, "Sends out a scan command to pair unlinked turtles")
function clearCommand() function clearCommand()
log.buffer = {} log.buffer = {}
end end
registerConsoleCommand("clear", clearCommand) registerConsoleCommand("clear", clearCommand, "Clears the console")
function turtlesCommand() function turtlesCommand()
if #turtles == 0 then if #turtles == 0 then
@@ -357,7 +362,15 @@ function turtlesCommand()
end end
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 drawing functions