From 27d32e99ed3bce458703cca666998c40e61d47a8 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Tue, 2 Sep 2025 17:28:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=B8=AE=E5=8A=A9=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0helplist=E5=91=BD=E4=BB=A4=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=88=97=E5=87=BA=E6=89=80=E6=9C=89=E5=B8=AE=E5=8A=A9=E4=B8=BB?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加helplist.lua程序用于列出所有可用的帮助主题,支持排序和彩色输出选项 同时添加test_helplist.lua测试脚本验证helplist命令功能 --- .../lua/rom/programs/helplist.lua | 63 +++++++++++++++++++ .../lua/rom/programs/test_helplist.lua | 63 +++++++++++++++++++ installer.lua | 2 +- 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 data/computercraft/lua/rom/programs/helplist.lua create mode 100644 data/computercraft/lua/rom/programs/test_helplist.lua diff --git a/data/computercraft/lua/rom/programs/helplist.lua b/data/computercraft/lua/rom/programs/helplist.lua new file mode 100644 index 0000000..ec06e25 --- /dev/null +++ b/data/computercraft/lua/rom/programs/helplist.lua @@ -0,0 +1,63 @@ +-- helplist.lua: List all available help documents +local help = require("help") +local textutils = require("textutils") +local term = require("term") +local colors = require("colors") + +-- Help information function +local function printHelp() + print("Usage: helplist [options]") + print("Options:") + print(" --help, -h Show this help message") + print(" --sort, -s Sort topics alphabetically") + print(" --color, -c Show colored output") + print([[ +Lists all available help topics in LeonOS.]]) +end + +-- Main function +local function main(args) + -- Process command line arguments + local showHelp = false + local sortTopics = false + local useColor = false + + for _, arg in ipairs(args) do + if arg == "--help" or arg == "-h" then + showHelp = true + elseif arg == "--sort" or arg == "-s" then + sortTopics = true + elseif arg == "--color" or arg == "-c" then + useColor = true + end + end + + if showHelp then + printHelp() + return + end + + -- Get all help topics + local topics = help.topics() + + -- Sort topics if requested + if sortTopics then + table.sort(topics) + end + + -- Display the help topics + print("Available help topics (" .. #topics .. "):") + for _, topic in ipairs(topics) do + if useColor then + term.setTextColor(colors.cyan) + print(" " .. topic) + term.setTextColor(colors.white) + else + print(" " .. topic) + end + end +end + +-- Run the main function +local args = {...} +main(args) \ No newline at end of file diff --git a/data/computercraft/lua/rom/programs/test_helplist.lua b/data/computercraft/lua/rom/programs/test_helplist.lua new file mode 100644 index 0000000..6cfc8bc --- /dev/null +++ b/data/computercraft/lua/rom/programs/test_helplist.lua @@ -0,0 +1,63 @@ +-- test_helplist.lua: Test the helplist command +local shell = require("shell") +local term = require("term") + +print("=== Testing helplist Command ===") +print("This test will run the helplist command with different options") +print("to verify it correctly lists all available help topics.") +print(" +Test 1: Basic helplist command") +os.sleep(1) +term.clear() +local success = shell.run("helplist") +if not success then + print("Error: helplist command failed to run.") +else + print(" +Test 1 completed. Press any key to continue.") +os.pullEvent("key") +end + +print(" +Test 2: helplist with sorting") +os.sleep(1) +term.clear() +success = shell.run("helplist", "--sort") +if not success then + print("Error: helplist --sort command failed to run.") +else + print(" +Test 2 completed. Press any key to continue.") +os.pullEvent("key") +end + +print(" +Test 3: helplist with color") +os.sleep(1) +term.clear() +success = shell.run("helplist", "--color") +if not success then + print("Error: helplist --color command failed to run.") +else + print(" +Test 3 completed. Press any key to continue.") +os.pullEvent("key") +end + +print(" +Test 4: helplist help") +os.sleep(1) +term.clear() +success = shell.run("helplist", "--help") +if not success then + print("Error: helplist --help command failed to run.") +else + print(" +Test 4 completed. Press any key to finish.") +os.pullEvent("key") +end + +term.clear() +print("=== helplist Command Tests Completed ===") +print("All tests have been executed.") +print("You can now use the 'helplist' command to list all available help topics.") \ No newline at end of file diff --git a/installer.lua b/installer.lua index 4b2033d..33de7fa 100644 --- a/installer.lua +++ b/installer.lua @@ -1,5 +1,5 @@ -- LeonOS installer -local INSTALLER_VERSION = "0.3.7 Beta 11" +local INSTALLER_VERSION = "0.3.7 Beta 12" local DEFAULT_ROM_DIR = "/leonos" print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")