aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2017-10-05 12:59:50 -0300
committerGitHub <noreply@github.com>2017-10-05 12:59:50 -0300
commit6898b379a8c25db3e21ba27b96680c7d0c5683f2 (patch)
tree9aa6a34d6d1cba40d37bed7ce99f69a60c52ff7b
parentd993464422e850689f73a6f7c35ae980ca3823d0 (diff)
downloadluarocks-6898b379a8c25db3e21ba27b96680c7d0c5683f2.tar.gz
luarocks-6898b379a8c25db3e21ba27b96680c7d0c5683f2.tar.bz2
luarocks-6898b379a8c25db3e21ba27b96680c7d0c5683f2.zip
Add `luarocks which` command. (#733)
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/cmd/which.lua30
-rw-r--r--src/luarocks/loader.lua7
3 files changed, 35 insertions, 3 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks
index 88a1d1ca..491809dd 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -28,6 +28,7 @@ commands = {
28 doc = "luarocks.cmd.doc", 28 doc = "luarocks.cmd.doc",
29 upload = "luarocks.cmd.upload", 29 upload = "luarocks.cmd.upload",
30 config = "luarocks.cmd.config", 30 config = "luarocks.cmd.config",
31 which = "luarocks.cmd.which",
31} 32}
32 33
33command_line.run_command(...) 34command_line.run_command(...)
diff --git a/src/luarocks/cmd/which.lua b/src/luarocks/cmd/which.lua
new file mode 100644
index 00000000..0116fdb8
--- /dev/null
+++ b/src/luarocks/cmd/which.lua
@@ -0,0 +1,30 @@
1
2--- @module luarocks.which_cmd
3-- Driver for the `luarocks which` command.
4local which_cmd = {}
5
6local loader = require("luarocks.loader")
7local cfg = require("luarocks.core.cfg")
8local util = require("luarocks.util")
9
10which_cmd.help_summary = "Tell which file corresponds to a given module name."
11which_cmd.help_arguments = "<modname>"
12which_cmd.help = [[
13Given a module name like "foo.bar", output which file would be loaded to resolve
14that module by luarocks.loader, like "/usr/local/lua/]]..cfg.lua_version..[[/foo/bar.lua".
15]]
16
17--- Driver function for "lua" command.
18-- @return boolean This function terminates the interpreter.
19function which_cmd.command(_, modname)
20 local pathname, rock_name, rock_version = loader.which(modname)
21 if not pathname then
22 return nil, "Module '" .. modname .. "' not found by luarocks.loader."
23 end
24 util.printout(pathname)
25 util.printout("(provided by " .. tostring(rock_name) .. " " .. tostring(rock_version) .. ")")
26 return true
27end
28
29return which_cmd
30
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index c8259689..84cdd696 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -222,10 +222,11 @@ end
222 222
223--- Return the pathname of the file that would be loaded for a module. 223--- Return the pathname of the file that would be loaded for a module.
224-- @param module string: module name (eg. "socket.core") 224-- @param module string: module name (eg. "socket.core")
225-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 225-- @return filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so"),
226-- the rock name and the rock version.
226function loader.which(module) 227function loader.which(module)
227 local _, _, file_name = select_module(module, path.which_i) 228 local rock_name, rock_version, file_name = select_module(module, path.which_i)
228 return file_name 229 return file_name, rock_name, rock_version
229end 230end
230 231
231--- Package loader for LuaRocks support. 232--- Package loader for LuaRocks support.