Files
Leonmmcoset c927b19cb2 feat: 更新安装程序版本并添加新功能和程序
更新安装程序版本至0.3.6 Beta 4
为shell程序添加package别名
新增applist程序用于列出/app目录下的应用
2025-09-02 12:30:03 +08:00

76 lines
1.8 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- applist.lua - List applications in /app directory
local fs = require("fs")
local tu = require("textutils")
local function show_help()
print("Usage: applist [options]")
print("Lists all applications in the /app directory")
print("")
print("Options:")
print(" --help, -h Show this help message")
print(" --verbose, -v Show more details about each application")
end
local function list_apps(verbose)
local app_dir = "/app"
-- 检查app目录是否存在
if not fs.exists(app_dir) then
print("No applications directory found at /app")
return
end
-- 获取app目录中的文件列表
local files = fs.list(app_dir)
if #files == 0 then
print("No applications installed in /app directory")
return
end
print("Installed applications:")
print("======================")
for _, file in ipairs(files) do
local file_path = fs.combine(app_dir, file)
local is_dir = fs.isDir(file_path)
if is_dir then
-- 如果是目录,可能是一个应用程序文件夹
print("[" .. file .. "]")
if verbose then
-- 在详细模式下,显示目录中的.lua文件
local sub_files = fs.list(file_path)
for _, sub_file in ipairs(sub_files) do
if sub_file:sub(-4) == ".lua" then
print(" - " .. sub_file)
end
end
end
elseif file:sub(-4) == ".lua" then
-- 如果是.lua文件直接显示
print(file:sub(1, -5)) -- 移除.lua扩展名
end
end
end
local function main(args)
local verbose = false
-- 解析命令行参数
for _, arg in ipairs(args) do
if arg == "--help" or arg == "-h" then
show_help()
return
elseif arg == "--verbose" or arg == "-v" then
verbose = true
end
end
list_apps(verbose)
end
-- 运行主函数
local args = {...}
main(args)