diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:00 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | d7e2df280c9855521ed8b428cf2566daba61c7ee (patch) | |
| tree | 1400d8c5f52dfd8a4aeb37c204e02f1e0508391c /src | |
| parent | 259b4ae048616d5a8dc92fc3e299796e2abafe89 (diff) | |
| download | luarocks-d7e2df280c9855521ed8b428cf2566daba61c7ee.tar.gz luarocks-d7e2df280c9855521ed8b428cf2566daba61c7ee.tar.bz2 luarocks-d7e2df280c9855521ed8b428cf2566daba61c7ee.zip | |
Teal: convert luarocks.cmd.list
Diffstat (limited to 'src')
| -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. |
| 4 | local list = {} | 4 | local record list |
| 5 | record Outdated | ||
| 6 | name: string | ||
| 7 | installed: string | ||
| 8 | available: string | ||
| 9 | repo: string | ||
| 10 | end | ||
| 11 | end | ||
| 5 | 12 | ||
| 6 | local search = require("luarocks.search") | 13 | local search = require("luarocks.search") |
| 7 | local queries = require("luarocks.queries") | 14 | local queries = require("luarocks.queries") |
| @@ -10,7 +17,17 @@ local cfg = require("luarocks.core.cfg") | |||
| 10 | local util = require("luarocks.util") | 17 | local util = require("luarocks.util") |
| 11 | local path = require("luarocks.path") | 18 | local path = require("luarocks.path") |
| 12 | 19 | ||
| 13 | function list.add_to_parser(parser) | 20 | local type Outdated = list.Outdated |
| 21 | |||
| 22 | local type Parser = require("luarocks.vendor.argparse").Parser | ||
| 23 | |||
| 24 | local type Args = require("luarocks.core.types.args").Args | ||
| 25 | |||
| 26 | local type Tree = require("luarocks.core.types.tree").Tree | ||
| 27 | |||
| 28 | local type Query = require("luarocks.core.types.query").Query | ||
| 29 | |||
| 30 | function 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.") |
| 24 | end | 41 | end |
| 25 | 42 | ||
| 26 | local function check_outdated(trees, query) | 43 | local 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 |
| 52 | end | 69 | end |
| 53 | 70 | ||
| 54 | local function list_outdated(trees, query, porcelain) | 71 | local 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. |
| 71 | function list.command(args) | 88 | function 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 |
