aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/cmd/list.tl (renamed from src/luarocks/cmd/list.lua)37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/luarocks/cmd/list.lua b/src/luarocks/cmd/list.tl
index 7b2682f6..9a0948f0 100644
--- a/src/luarocks/cmd/list.lua
+++ b/src/luarocks/cmd/list.tl
@@ -1,7 +1,14 @@
1 1
2--- Module implementing the LuaRocks "list" command. 2--- Module implementing the LuaRocks "list" command.
3-- Lists currently installed rocks. 3-- Lists currently installed rocks.
4local list = {} 4local record list
5 record Outdated
6 name: string
7 installed: string
8 available: string
9 repo: string
10 end
11end
5 12
6local search = require("luarocks.search") 13local search = require("luarocks.search")
7local queries = require("luarocks.queries") 14local queries = require("luarocks.queries")
@@ -10,7 +17,17 @@ local cfg = require("luarocks.core.cfg")
10local util = require("luarocks.util") 17local util = require("luarocks.util")
11local path = require("luarocks.path") 18local path = require("luarocks.path")
12 19
13function list.add_to_parser(parser) 20local type Outdated = list.Outdated
21
22local type Parser = require("luarocks.vendor.argparse").Parser
23
24local type Args = require("luarocks.core.types.args").Args
25
26local type Tree = require("luarocks.core.types.tree").Tree
27
28local type Query = require("luarocks.core.types.query").Query
29
30function list.add_to_parser(parser: Parser)
14 local cmd = parser:command("list", "List currently installed rocks.", util.see_also()) 31 local cmd = parser:command("list", "List currently installed rocks.", util.see_also())
15 32
16 cmd:argument("filter", "A substring of a rock name to filter by.") 33 cmd:argument("filter", "A substring of a rock name to filter by.")
@@ -23,19 +40,19 @@ function list.add_to_parser(parser)
23 cmd:flag("--porcelain", "Produce machine-friendly output.") 40 cmd:flag("--porcelain", "Produce machine-friendly output.")
24end 41end
25 42
26local function check_outdated(trees, query) 43local function check_outdated(trees: {string | Tree}, query: Query): {Outdated}
27 local results_installed = {} 44 local results_installed = {}
28 for _, tree in ipairs(trees) do 45 for _, tree in ipairs(trees) do
29 search.local_manifest_search(results_installed, path.rocks_dir(tree), query) 46 search.local_manifest_search(results_installed, path.rocks_dir(tree), query)
30 end 47 end
31 local outdated = {} 48 local outdated: {Outdated} = {}
32 for name, versions in util.sortedpairs(results_installed) do 49 for name, versions in util.sortedpairs(results_installed) do
33 versions = util.keys(versions) 50 local versionsk = util.keys(versions)
34 table.sort(versions, vers.compare_versions) 51 table.sort(versionsk, vers.compare_versions)
35 local latest_installed = versions[1] 52 local latest_installed = versionsk[1]
36 53
37 local query_available = queries.new(name:lower()) 54 local query_available = queries.new(name:lower())
38 local results_available, err = search.search_repos(query_available) 55 local results_available = search.search_repos(query_available)
39 56
40 if results_available[name] then 57 if results_available[name] then
41 local available_versions = util.keys(results_available[name]) 58 local available_versions = util.keys(results_available[name])
@@ -51,7 +68,7 @@ local function check_outdated(trees, query)
51 return outdated 68 return outdated
52end 69end
53 70
54local function list_outdated(trees, query, porcelain) 71local function list_outdated(trees: {string | Tree}, query: Query, porcelain: boolean): boolean
55 util.title("Outdated rocks:", porcelain) 72 util.title("Outdated rocks:", porcelain)
56 local outdated = check_outdated(trees, query) 73 local outdated = check_outdated(trees, query)
57 for _, item in ipairs(outdated) do 74 for _, item in ipairs(outdated) do
@@ -68,7 +85,7 @@ end
68 85
69--- Driver function for "list" command. 86--- Driver function for "list" command.
70-- @return boolean: True if succeeded, nil on errors. 87-- @return boolean: True if succeeded, nil on errors.
71function list.command(args) 88function list.command(args: Args): boolean, string
72 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true) 89 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true)
73 local trees = cfg.rocks_trees 90 local trees = cfg.rocks_trees
74 local title = "Rocks installed for Lua "..cfg.lua_version 91 local title = "Rocks installed for Lua "..cfg.lua_version