aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-04-13 12:29:15 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-04-13 17:11:12 -0300
commitd33b56cd60d623500c88b8bd2924e6674fc22776 (patch)
tree6771492414e7ab768559d33fafd01dd654bf8a12
parent277baba01e09a1456e4aeb8afcd1f29c1d2eefbc (diff)
downloadluarocks-d33b56cd60d623500c88b8bd2924e6674fc22776.tar.gz
luarocks-d33b56cd60d623500c88b8bd2924e6674fc22776.tar.bz2
luarocks-d33b56cd60d623500c88b8bd2924e6674fc22776.zip
Display namespaces in `luarocks show`
-rw-r--r--spec/show_spec.lua5
-rw-r--r--src/luarocks/cmd/show.lua8
-rw-r--r--src/luarocks/path.lua19
-rw-r--r--src/luarocks/search.lua55
-rw-r--r--src/luarocks/util.lua1
5 files changed, 54 insertions, 34 deletions
diff --git a/spec/show_spec.lua b/spec/show_spec.lua
index 4880106d..a3f856fd 100644
--- a/spec/show_spec.lua
+++ b/spec/show_spec.lua
@@ -88,4 +88,9 @@ describe("LuaRocks show #blackbox #b_show", function()
88 assert.match("a_build_dep", run.luarocks("show has_build_dep --build-deps")) 88 assert.match("a_build_dep", run.luarocks("show has_build_dep --build-deps"))
89 end) 89 end)
90 90
91 it("shows #namespaces via --rock-namespace", function()
92 assert(run.luarocks_bool("build a_user/a_rock --server=" .. testing_paths.fixtures_dir .. "/a_repo" ))
93 assert.match("a_user", run.luarocks("show a_rock --rock-namespace"))
94 end)
95
91end) 96end)
diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua
index dfd2f3de..b76ff778 100644
--- a/src/luarocks/cmd/show.lua
+++ b/src/luarocks/cmd/show.lua
@@ -91,8 +91,9 @@ function show.command(flags, name, version)
91 if not name then 91 if not name then
92 return nil, version 92 return nil, version
93 end 93 end
94 94 local tree = path.rocks_tree_to_string(repo)
95 local directory = path.install_dir(name, version, repo) 95 local directory = path.install_dir(name, version, repo)
96 local namespace = path.read_namespace(name, version, tree)
96 local rockspec_file = path.rockspec_file(name, version, repo) 97 local rockspec_file = path.rockspec_file(name, version, repo)
97 local rockspec, err = fetch.load_local_rockspec(rockspec_file) 98 local rockspec, err = fetch.load_local_rockspec(rockspec_file)
98 if not rockspec then return nil,err end 99 if not rockspec then return nil,err end
@@ -102,7 +103,8 @@ function show.command(flags, name, version)
102 if not manifest then return nil,err end 103 if not manifest then return nil,err end
103 local minfo = manifest.repository[name][version][1] 104 local minfo = manifest.repository[name][version][1]
104 105
105 if flags["rock-tree"] then util.printout(path.rocks_tree_to_string(repo)) 106 if flags["rock-tree"] then util.printout(tree)
107 elseif flags["rock-namespace"] then util.printout(namespace)
106 elseif flags["rock-dir"] then util.printout(directory) 108 elseif flags["rock-dir"] then util.printout(directory)
107 elseif flags["home"] then util.printout(descript.homepage) 109 elseif flags["home"] then util.printout(descript.homepage)
108 elseif flags["issues"] then util.printout(descript.issues_url) 110 elseif flags["issues"] then util.printout(descript.issues_url)
@@ -120,7 +122,7 @@ function show.command(flags, name, version)
120 elseif flags["mversion"] then util.printout(version) 122 elseif flags["mversion"] then util.printout(version)
121 else 123 else
122 util.printout() 124 util.printout()
123 util.printout(rockspec.package.." "..rockspec.version.." - "..(descript.summary or "")) 125 util.printout((namespace and namespace .."/" or "") .. rockspec.package.." "..rockspec.version.." - "..(descript.summary or ""))
124 util.printout() 126 util.printout()
125 if descript.detailed then 127 if descript.detailed then
126 util.printout(format_text(descript.detailed)) 128 util.printout(format_text(descript.detailed))
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index f6b12727..4babcb30 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -287,4 +287,23 @@ function path.map_trees(deps_mode, fn, ...)
287 return result 287 return result
288end 288end
289 289
290--- Get the namespace of a locally-installed rock, if any.
291-- @param name string: The rock name, without a namespace.
292-- @param version string: The rock version.
293-- @param tree string: The local tree to use.
294-- @return string?: The namespace if it exists, or nil.
295function path.read_namespace(name, version, tree)
296 assert(type(name) == "string" and not name:match("/"))
297 assert(type(version) == "string")
298 assert(type(tree) == "string")
299
300 local namespace
301 local fd = io.open(path.rock_namespace_file(name, version, tree), "r")
302 if fd then
303 namespace = fd:read("*a")
304 fd:close()
305 end
306 return namespace
307end
308
290return path 309return path
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 49098642..57f39bdc 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -25,7 +25,8 @@ function search.store_result(result_tree, result)
25 if not result_tree[name][version] then result_tree[name][version] = {} end 25 if not result_tree[name][version] then result_tree[name][version] = {} end
26 table.insert(result_tree[name][version], { 26 table.insert(result_tree[name][version], {
27 arch = result.arch, 27 arch = result.arch,
28 repo = result.repo 28 repo = result.repo,
29 namespace = result.namespace,
29 }) 30 })
30end 31end
31 32
@@ -47,25 +48,6 @@ local function store_if_match(result_tree, result, query)
47 end 48 end
48end 49end
49 50
50--- Get the namespace of a locally-installed rock, if any.
51-- @param name string: The rock name, without a namespace.
52-- @param version string: The rock version.
53-- @param tree string: The local tree to use.
54-- @return string?: The namespace if it exists, or nil.
55local function read_namespace(name, version, tree)
56 assert(type(name) == "string" and not name:match("/"))
57 assert(type(version) == "string")
58 assert(type(tree) == "string")
59
60 local namespace
61 local fd = io.open(path.rock_namespace_file(name, version, tree), "r")
62 if fd then
63 namespace = fd:read("*a")
64 fd:close()
65 end
66 return namespace
67end
68
69--- Perform search on a local repository. 51--- Perform search on a local repository.
70-- @param repo string: The pathname of the local repository. 52-- @param repo string: The pathname of the local repository.
71-- @param query table: a query object. 53-- @param query table: a query object.
@@ -96,7 +78,7 @@ function search.disk_search(repo, query, result_tree)
96 elseif fs.is_dir(pathname) then 78 elseif fs.is_dir(pathname) then
97 for version in fs.dir(pathname) do 79 for version in fs.dir(pathname) do
98 if version:match("-%d+$") then 80 if version:match("-%d+$") then
99 local namespace = read_namespace(name, version, repo) 81 local namespace = path.read_namespace(name, version, repo)
100 local result = results.new(name, version, repo, "installed", namespace) 82 local result = results.new(name, version, repo, "installed", namespace)
101 store_if_match(result_tree, result, query) 83 store_if_match(result_tree, result, query)
102 end 84 end
@@ -132,7 +114,7 @@ local function manifest_search(result_tree, repo, query, lua_version, is_local)
132 end 114 end
133 for name, versions in pairs(manifest.repository) do 115 for name, versions in pairs(manifest.repository) do
134 for version, items in pairs(versions) do 116 for version, items in pairs(versions) do
135 local namespace = is_local and read_namespace(name, version, repo) or query.namespace 117 local namespace = is_local and path.read_namespace(name, version, repo) or query.namespace
136 for _, item in ipairs(items) do 118 for _, item in ipairs(items) do
137 local result = results.new(name, version, repo, item.arch, namespace) 119 local result = results.new(name, version, repo, item.arch, namespace)
138 store_if_match(result_tree, result, query) 120 store_if_match(result_tree, result, query)
@@ -292,21 +274,32 @@ function search.print_result_tree(result_tree, porcelain)
292 assert(type(result_tree) == "table") 274 assert(type(result_tree) == "table")
293 assert(type(porcelain) == "boolean" or not porcelain) 275 assert(type(porcelain) == "boolean" or not porcelain)
294 276
295 for package, versions in util.sortedpairs(result_tree) do 277 if porcelain then
296 if not porcelain then 278 for package, versions in util.sortedpairs(result_tree) do
297 util.printout(package) 279 for version, repos in util.sortedpairs(versions, vers.compare_versions) do
280 for _, repo in ipairs(repos) do
281 local nrepo = dir.normalize(repo.repo)
282 util.printout(package, version, repo.arch, nrepo, repo.namespace)
283 end
284 end
298 end 285 end
286 return
287 end
288
289 for package, versions in util.sortedpairs(result_tree) do
290 local namespaces = {}
299 for version, repos in util.sortedpairs(versions, vers.compare_versions) do 291 for version, repos in util.sortedpairs(versions, vers.compare_versions) do
300 for _, repo in ipairs(repos) do 292 for _, repo in ipairs(repos) do
293 local key = repo.namespace or ""
294 local list = namespaces[key] or {}
295 namespaces[key] = list
296
301 repo.repo = dir.normalize(repo.repo) 297 repo.repo = dir.normalize(repo.repo)
302 if porcelain then 298 table.insert(list, " "..version.." ("..repo.arch..") - "..repo.repo)
303 util.printout(package, version, repo.arch, repo.repo)
304 else
305 util.printout(" "..version.." ("..repo.arch..") - "..repo.repo)
306 end
307 end 299 end
308 end 300 end
309 if not porcelain then 301 for key, list in util.sortedpairs(namespaces) do
302 util.printout(key == "" and package or key .. "/" .. package)
310 util.printout() 303 util.printout()
311 end 304 end
312 end 305 end
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index c797fa80..6dd96e0d 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -130,6 +130,7 @@ local supported_flags = {
130 ["porcelain"] = true, 130 ["porcelain"] = true,
131 ["quick"] = true, 131 ["quick"] = true,
132 ["rock-dir"] = true, 132 ["rock-dir"] = true,
133 ["rock-namespace"] = true,
133 ["rock-tree"] = true, 134 ["rock-tree"] = true,
134 ["rock-trees"] = true, 135 ["rock-trees"] = true,
135 ["rockspec"] = true, 136 ["rockspec"] = true,