diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/which.lua | 25 |
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 = {} | |||
| 6 | local loader = require("luarocks.loader") | 6 | local loader = require("luarocks.loader") |
| 7 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
| 8 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 9 | local fs = require("luarocks.fs") | ||
| 9 | 10 | ||
| 10 | which_cmd.help_summary = "Tell which file corresponds to a given module name." | 11 | which_cmd.help_summary = "Tell which file corresponds to a given module name." |
| 11 | which_cmd.help_arguments = "<modname>" | 12 | which_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 | ||
| 30 | end | 45 | end |
| 31 | 46 | ||
| 32 | return which_cmd | 47 | return which_cmd |
