feat: add usage
This commit is contained in:
@@ -267,11 +267,12 @@ registerEventListener("key", scrollLogs)
|
||||
local consoleCommands = {}
|
||||
local commandBuffer = ""
|
||||
|
||||
function registerConsoleCommand(name, handler, desc)
|
||||
function registerConsoleCommand(name, handler, desc, usage)
|
||||
local cmd = {
|
||||
["name"] = name,
|
||||
["handler"] = handler,
|
||||
["desc"] = desc or ""
|
||||
["desc"] = desc or "",
|
||||
["usage"] = usage or nil
|
||||
}
|
||||
consoleCommands[name] = cmd
|
||||
end
|
||||
@@ -324,7 +325,7 @@ function echoCommand(args)
|
||||
log.info(table.concat(args, " "))
|
||||
end
|
||||
|
||||
registerConsoleCommand("echo", echoCommand, "Prints your message")
|
||||
registerConsoleCommand("echo", echoCommand, "Prints your message", "echo (string)")
|
||||
|
||||
function exitCommand(args)
|
||||
shouldRun = false
|
||||
@@ -339,13 +340,13 @@ end
|
||||
|
||||
registerConsoleCommand("scan", scanCommand, "Sends out a scan command to pair unlinked turtles")
|
||||
|
||||
function clearCommand()
|
||||
function clearCommand(args)
|
||||
log.buffer = {}
|
||||
end
|
||||
|
||||
registerConsoleCommand("clear", clearCommand, "Clears the console")
|
||||
|
||||
function turtlesCommand()
|
||||
function turtlesCommand(args)
|
||||
if #turtles == 0 then
|
||||
log.info("no turtles registered")
|
||||
return
|
||||
@@ -364,11 +365,14 @@ end
|
||||
|
||||
registerConsoleCommand("turtles", turtlesCommand, "Lists all the linked turtles")
|
||||
|
||||
function helpCommand()
|
||||
function helpCommand(args)
|
||||
log.info("----- commands -----")
|
||||
for _, cmd in pairs(consoleCommands) do
|
||||
log.info("* %s", cmd.name)
|
||||
log.info("\t%s", cmd.desc)
|
||||
log.info("\t\t%s", cmd.desc)
|
||||
if cmd.usage then
|
||||
log.info("Usage: %s", cmd.usage)
|
||||
end
|
||||
end
|
||||
end
|
||||
registerConsoleCommand("help", helpCommand, "Prints out all the console commands")
|
||||
|
||||
Reference in New Issue
Block a user