feat: add command descriptions and help cmd
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user