File size: 3,530 Bytes
d7c5875 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table
local list = { Outdated = {} }
local search = require("luarocks.search")
local queries = require("luarocks.queries")
local vers = require("luarocks.core.vers")
local cfg = require("luarocks.core.cfg")
local util = require("luarocks.util")
local path = require("luarocks.path")
function list.add_to_parser(parser)
local cmd = parser:command("list", "List currently installed rocks.", util.see_also())
cmd:argument("filter", "A substring of a rock name to filter by."):
args("?")
cmd:argument("version", "Rock version to filter by."):
args("?")
cmd:flag("--outdated", "List only rocks for which there is a higher " ..
"version available in the rocks server.")
cmd:flag("--porcelain", "Produce machine-friendly output.")
end
local function check_outdated(trees, query)
local results_installed = {}
for _, tree in ipairs(trees) do
search.local_manifest_search(results_installed, path.rocks_dir(tree), query)
end
local outdated = {}
for name, versions in util.sortedpairs(results_installed) do
local versionsk = util.keys(versions)
table.sort(versionsk, vers.compare_versions)
local latest_installed = versionsk[1]
local query_available = queries.new(name:lower())
local results_available = search.search_repos(query_available)
if results_available[name] then
local available_versions = util.keys(results_available[name])
table.sort(available_versions, vers.compare_versions)
local latest_available = available_versions[1]
local latest_available_repo = results_available[name][latest_available][1].repo
if vers.compare_versions(latest_available, latest_installed) then
table.insert(outdated, { name = name, installed = latest_installed, available = latest_available, repo = latest_available_repo })
end
end
end
return outdated
end
local function list_outdated(trees, query, porcelain)
util.title("Outdated rocks:", porcelain)
local outdated = check_outdated(trees, query)
for _, item in ipairs(outdated) do
if porcelain then
util.printout(item.name, item.installed, item.available, item.repo)
else
util.printout(item.name)
util.printout(" " .. item.installed .. " < " .. item.available .. " at " .. item.repo)
util.printout()
end
end
return true
end
function list.command(args)
local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true)
local trees = cfg.rocks_trees
local title = "Rocks installed for Lua " .. cfg.lua_version
if args.tree then
trees = { args.tree }
title = title .. " in " .. args.tree
end
if args.outdated then
return list_outdated(trees, query, args.porcelain)
end
local results = {}
for _, tree in ipairs(trees) do
local ok, err, errcode = search.local_manifest_search(results, path.rocks_dir(tree), query)
if not ok and errcode ~= "open" then
util.warning(err)
end
end
util.title(title, args.porcelain)
search.print_result_tree(results, args.porcelain)
return true
end
return list
|