aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2019-07-12 17:38:00 -0300
committerHisham Muhammad <hisham@gobolinux.org>2019-07-12 17:38:00 -0300
commitec78ef6b0f4dc866a803b4e6d23ad16db12934d6 (patch)
tree82ddf444389ea579d2fc5431e08893bd0624bbcf /src
parent6c7dfb00fa6d097319630fcc38123c30a34d1784 (diff)
downloadluarocks-ec78ef6b0f4dc866a803b4e6d23ad16db12934d6.tar.gz
luarocks-ec78ef6b0f4dc866a803b4e6d23ad16db12934d6.tar.bz2
luarocks-ec78ef6b0f4dc866a803b4e6d23ad16db12934d6.zip
which: search in package.path and cpath as well
Also, add some tests.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cmd/which.lua25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/luarocks/cmd/which.lua b/src/luarocks/cmd/which.lua
index 89e6db56..56db5254 100644
--- a/src/luarocks/cmd/which.lua
+++ b/src/luarocks/cmd/which.lua
@@ -6,6 +6,7 @@ local which_cmd = {}
6local loader = require("luarocks.loader") 6local loader = require("luarocks.loader")
7local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8local util = require("luarocks.util") 8local util = require("luarocks.util")
9local fs = require("luarocks.fs")
9 10
10which_cmd.help_summary = "Tell which file corresponds to a given module name." 11which_cmd.help_summary = "Tell which file corresponds to a given module name."
11which_cmd.help_arguments = "<modname>" 12which_cmd.help_arguments = "<modname>"
@@ -21,12 +22,26 @@ function which_cmd.command(_, modname)
21 return nil, "Missing module name. " .. util.see_help("which") 22 return nil, "Missing module name. " .. util.see_help("which")
22 end 23 end
23 local pathname, rock_name, rock_version = loader.which(modname) 24 local pathname, rock_name, rock_version = loader.which(modname)
24 if not pathname then 25
25 return nil, "Module '" .. modname .. "' not found by luarocks.loader." 26 if pathname then
27 util.printout(pathname)
28 util.printout("(provided by " .. tostring(rock_name) .. " " .. tostring(rock_version) .. ")")
29 return true
30 end
31
32 local modpath = modname:gsub("%.", "/")
33 for _, v in ipairs({"path", "cpath"}) do
34 for p in package[v]:gmatch("([^;]+)") do
35 local pathname = p:gsub("%?", modpath)
36 if fs.exists(pathname) then
37 util.printout(pathname)
38 util.printout("(found directly via package." .. v .. " -- not installed as a rock?)")
39 return true
40 end
41 end
26 end 42 end
27 util.printout(pathname) 43
28 util.printout("(provided by " .. tostring(rock_name) .. " " .. tostring(rock_version) .. ")") 44 return nil, "Module '" .. modname .. "' not found."
29 return true
30end 45end
31 46
32return which_cmd 47return which_cmd