aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-09-10 14:54:04 -0300
committerHisham Muhammad <hisham@gobolinux.org>2014-09-10 14:54:04 -0300
commite5cd7a90d78f5ffb40d4e8ee6a2b6396d6aa574c (patch)
treeac4efc390b0685fbf98e340dd6041192211bb8f5
parentf0d66aeacd60e6df926a55ecb9a08e6f802f9242 (diff)
downloadluarocks-e5cd7a90d78f5ffb40d4e8ee6a2b6396d6aa574c.tar.gz
luarocks-e5cd7a90d78f5ffb40d4e8ee6a2b6396d6aa574c.tar.bz2
luarocks-e5cd7a90d78f5ffb40d4e8ee6a2b6396d6aa574c.zip
Add --outdated as a flag to `luarocks list`.
A variation of the feature suggested in #282.
-rw-r--r--src/luarocks/list.lua63
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 = {}
6package.loaded["luarocks.list"] = list 6package.loaded["luarocks.list"] = list
7 7
8local search = require("luarocks.search") 8local search = require("luarocks.search")
9local deps = require("luarocks.deps")
9local cfg = require("luarocks.cfg") 10local cfg = require("luarocks.cfg")
10local util = require("luarocks.util") 11local util = require("luarocks.util")
11local path = require("luarocks.path") 12local path = require("luarocks.path")
@@ -15,22 +16,82 @@ list.help_arguments = "[--porcelain] <filter>"
15list.help = [[ 16list.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
25local 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
60end
61
62local 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
75end
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.
25function list.run(...) 81function 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