diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/list.lua | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index 319909d3..71ebaf5a 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua | |||
@@ -6,6 +6,7 @@ local list = {} | |||
6 | package.loaded["luarocks.list"] = list | 6 | package.loaded["luarocks.list"] = list |
7 | 7 | ||
8 | local search = require("luarocks.search") | 8 | local search = require("luarocks.search") |
9 | local deps = require("luarocks.deps") | ||
9 | local cfg = require("luarocks.cfg") | 10 | local cfg = require("luarocks.cfg") |
10 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
11 | local path = require("luarocks.path") | 12 | local path = require("luarocks.path") |
@@ -15,22 +16,82 @@ list.help_arguments = "[--porcelain] <filter>" | |||
15 | list.help = [[ | 16 | list.help = [[ |
16 | <filter> is a substring of a rock name to filter by. | 17 | <filter> is a substring of a rock name to filter by. |
17 | 18 | ||
19 | --outdated List only rocks for which there is a | ||
20 | higher version available in the rocks server. | ||
21 | |||
18 | --porcelain Produce machine-friendly output. | 22 | --porcelain Produce machine-friendly output. |
19 | ]] | 23 | ]] |
20 | 24 | ||
25 | local function check_outdated(trees, query) | ||
26 | local results_installed = {} | ||
27 | for _, tree in ipairs(trees) do | ||
28 | search.manifest_search(results_installed, path.rocks_dir(tree), query) | ||
29 | end | ||
30 | local outdated = {} | ||
31 | for name, versions in util.sortedpairs(results_installed) do | ||
32 | local latest_installed | ||
33 | local latest_available, latest_available_repo | ||
34 | |||
35 | for version, _ in util.sortedpairs(versions) do | ||
36 | latest_installed = version | ||
37 | break | ||
38 | end | ||
39 | |||
40 | local query_available = search.make_query(name:lower()) | ||
41 | query.exact_name = true | ||
42 | local results_available, err = search.search_repos(query_available) | ||
43 | |||
44 | if results_available[name] then | ||
45 | for version, repos in util.sortedpairs(results_available[name], deps.compare_versions) do | ||
46 | latest_available = version | ||
47 | for _, repo in ipairs(repos) do | ||
48 | latest_available_repo = repo.repo | ||
49 | break | ||
50 | end | ||
51 | break | ||
52 | end | ||
53 | |||
54 | if deps.compare_versions(latest_available, latest_installed) then | ||
55 | table.insert(outdated, { name = name, installed = latest_installed, available = latest_available, repo = latest_available_repo }) | ||
56 | end | ||
57 | end | ||
58 | end | ||
59 | return outdated | ||
60 | end | ||
61 | |||
62 | local function list_outdated(trees, query, porcelain) | ||
63 | util.title("Outdated rocks:", porcelain) | ||
64 | local outdated = check_outdated(trees, query) | ||
65 | for _, item in ipairs(outdated) do | ||
66 | if porcelain then | ||
67 | util.printout(item.name, item.installed, item.available, item.repo) | ||
68 | else | ||
69 | util.printout(item.name) | ||
70 | util.printout(" "..item.installed.." < "..item.available.." at "..item.repo) | ||
71 | util.printout() | ||
72 | end | ||
73 | end | ||
74 | return true | ||
75 | end | ||
76 | |||
21 | --- Driver function for "list" command. | 77 | --- Driver function for "list" command. |
22 | -- @param filter string or nil: A substring of a rock name to filter by. | 78 | -- @param filter string or nil: A substring of a rock name to filter by. |
23 | -- @param version string or nil: a version may also be passed. | 79 | -- @param version string or nil: a version may also be passed. |
24 | -- @return boolean: True if succeeded, nil on errors. | 80 | -- @return boolean: True if succeeded, nil on errors. |
25 | function list.run(...) | 81 | function list.run(...) |
26 | local flags, filter, version = util.parse_flags(...) | 82 | local flags, filter, version = util.parse_flags(...) |
27 | local results = {} | ||
28 | local query = search.make_query(filter and filter:lower() or "", version) | 83 | local query = search.make_query(filter and filter:lower() or "", version) |
29 | query.exact_name = false | 84 | query.exact_name = false |
30 | local trees = cfg.rocks_trees | 85 | local trees = cfg.rocks_trees |
31 | if flags["tree"] then | 86 | if flags["tree"] then |
32 | trees = { flags["tree"] } | 87 | trees = { flags["tree"] } |
33 | end | 88 | end |
89 | |||
90 | if flags["outdated"] then | ||
91 | return list_outdated(trees, query, flags["porcelain"]) | ||
92 | end | ||
93 | |||
94 | local results = {} | ||
34 | for _, tree in ipairs(trees) do | 95 | for _, tree in ipairs(trees) do |
35 | search.manifest_search(results, path.rocks_dir(tree), query) | 96 | search.manifest_search(results, path.rocks_dir(tree), query) |
36 | end | 97 | end |