diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/bin/luarocks | 1 | ||||
| -rw-r--r-- | src/luarocks/search.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/show.lua | 136 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 27 |
4 files changed, 166 insertions, 1 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks index fd0c1d9c..5da4bc25 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
| @@ -17,5 +17,6 @@ commands.remove = require("luarocks.remove") | |||
| 17 | commands.make = require("luarocks.make") | 17 | commands.make = require("luarocks.make") |
| 18 | commands.download = require("luarocks.download") | 18 | commands.download = require("luarocks.download") |
| 19 | commands.path = require("luarocks.path") | 19 | commands.path = require("luarocks.path") |
| 20 | commands.show = require("luarocks.show") | ||
| 20 | 21 | ||
| 21 | command_line.run_command(...) | 22 | command_line.run_command(...) |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 6303eb8c..97b86a45 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
| @@ -283,8 +283,9 @@ end | |||
| 283 | -- @param results table: A table where keys are package names and versions | 283 | -- @param results table: A table where keys are package names and versions |
| 284 | -- are tables matching version strings to an array of rocks servers. | 284 | -- are tables matching version strings to an array of rocks servers. |
| 285 | -- @param show_repo boolean or nil: Whether to show repository | 285 | -- @param show_repo boolean or nil: Whether to show repository |
| 286 | -- @param long boolean or nil: Whether to show module files | ||
| 286 | -- information or not. Default is true. | 287 | -- information or not. Default is true. |
| 287 | function print_results(results, show_repo) | 288 | function print_results(results, show_repo, long) |
| 288 | assert(type(results) == "table") | 289 | assert(type(results) == "table") |
| 289 | assert(type(show_repo) == "boolean" or not show_repo) | 290 | assert(type(show_repo) == "boolean" or not show_repo) |
| 290 | -- Force display of repo location for the time being | 291 | -- Force display of repo location for the time being |
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua new file mode 100644 index 00000000..fcdffb9c --- /dev/null +++ b/src/luarocks/show.lua | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | |||
| 2 | --- Module implementing the LuaRocks "show" command. | ||
| 3 | -- Shows information about an installed rock. | ||
| 4 | module("luarocks.show", package.seeall) | ||
| 5 | |||
| 6 | local search = require("luarocks.search") | ||
| 7 | local cfg = require("luarocks.cfg") | ||
| 8 | local util = require("luarocks.util") | ||
| 9 | local path = require("luarocks.path") | ||
| 10 | local dir = require("luarocks.dir") | ||
| 11 | local deps = require("luarocks.deps") | ||
| 12 | local fetch = require("luarocks.fetch") | ||
| 13 | local manif = require("luarocks.manif") | ||
| 14 | help_summary = "Shows information about an installed rock." | ||
| 15 | |||
| 16 | help = [[ | ||
| 17 | <argument> is an existing package name. | ||
| 18 | Without any flags, show all module information. | ||
| 19 | With these flags, return only the desired information: | ||
| 20 | |||
| 21 | --home home page of project | ||
| 22 | --modules all modules provided by this package as used by require() | ||
| 23 | --deps packages this package depends on | ||
| 24 | --rockspec the full path of the rockspec file | ||
| 25 | --mversion the package version | ||
| 26 | --tree local tree where rock is installed | ||
| 27 | --rock-dir data directory of the installed rock | ||
| 28 | ]] | ||
| 29 | |||
| 30 | local function keys_as_string(t, sep) | ||
| 31 | return table.concat(util.keys(t), sep or " ") | ||
| 32 | end | ||
| 33 | |||
| 34 | local function word_wrap(line) | ||
| 35 | local width = tonumber(os.getenv("COLUMNS")) or 80 | ||
| 36 | if width > 80 then width = 80 end | ||
| 37 | if #line > width then | ||
| 38 | local brk = width | ||
| 39 | while brk > 0 and line:sub(brk, brk) ~= " " do | ||
| 40 | brk = brk - 1 | ||
| 41 | end | ||
| 42 | if brk > 0 then | ||
| 43 | return line:sub(1, brk-1) .. "\n" .. word_wrap(line:sub(brk+1)) | ||
| 44 | end | ||
| 45 | end | ||
| 46 | return line | ||
| 47 | end | ||
| 48 | |||
| 49 | local function format_text(text) | ||
| 50 | text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2") | ||
| 51 | local paragraphs = util.split_string(text, "\n\n") | ||
| 52 | for n, line in ipairs(paragraphs) do | ||
| 53 | paragraphs[n] = word_wrap(line) | ||
| 54 | end | ||
| 55 | return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) | ||
| 56 | end | ||
| 57 | |||
| 58 | --- Driver function for "show" command. | ||
| 59 | -- @param name or nil: an existing package name. | ||
| 60 | -- @param version string or nil: a version may also be passed. | ||
| 61 | -- @return boolean: True if succeeded, nil on errors. | ||
| 62 | function run(...) | ||
| 63 | local flags, name, version = util.parse_flags(...) | ||
| 64 | if not name then | ||
| 65 | return nil, "Argument missing, see help." | ||
| 66 | end | ||
| 67 | local results = {} | ||
| 68 | local query = search.make_query(name, version) | ||
| 69 | query.exact_name = true | ||
| 70 | local tree_map = {} | ||
| 71 | for _, tree in ipairs(cfg.rocks_trees) do | ||
| 72 | local rocks_dir = path.rocks_dir(tree) | ||
| 73 | tree_map[rocks_dir] = tree | ||
| 74 | search.manifest_search(results, rocks_dir, query) | ||
| 75 | end | ||
| 76 | |||
| 77 | if not next(results) then -- | ||
| 78 | return nil,"cannot find package "..name.."\nUse 'list' to find installed rocks" | ||
| 79 | end | ||
| 80 | |||
| 81 | local version,repo_url | ||
| 82 | local package, versions = util.sortedpairs(results)() | ||
| 83 | --question: what do we do about multiple versions? This should | ||
| 84 | --give us the latest version on the last repo (which is usually the global one) | ||
| 85 | for vs, repos in util.sortedpairs(versions, deps.compare_versions) do | ||
| 86 | version = vs | ||
| 87 | for _, rp in ipairs(repos) do repo_url = rp.repo end | ||
| 88 | end | ||
| 89 | |||
| 90 | |||
| 91 | local repo = tree_map[repo_url] | ||
| 92 | local directory = path.install_dir(name,version,repo) | ||
| 93 | local rockspec_file = path.rockspec_file(name, version, repo) | ||
| 94 | local rockspec, err = fetch.load_local_rockspec(rockspec_file) | ||
| 95 | if not rockspec then return nil,err end | ||
| 96 | |||
| 97 | local descript = rockspec.description | ||
| 98 | local manifest, err = manif.load_manifest(repo_url) | ||
| 99 | if not manifest then return nil,err end | ||
| 100 | local minfo = manifest.repository[name][version][1] | ||
| 101 | |||
| 102 | if flags["tree"] then print(repo) | ||
| 103 | elseif flags["rock-dir"] then print(directory) | ||
| 104 | elseif flags["home"] then print(descript.homepage) | ||
| 105 | elseif flags["modules"] then print(keys_as_string(minfo.modules)) | ||
| 106 | elseif flags["deps"] then print(keys_as_string(minfo.dependencies)) | ||
| 107 | elseif flags["rockspec"] then print(rockspec_file) | ||
| 108 | elseif flags["mversion"] then print(version) | ||
| 109 | else | ||
| 110 | print() | ||
| 111 | print(rockspec.package.." "..rockspec.version.." - "..descript.summary) | ||
| 112 | print() | ||
| 113 | print(format_text(descript.detailed)) | ||
| 114 | print() | ||
| 115 | if descript.license then | ||
| 116 | print("License: ", descript.license) | ||
| 117 | end | ||
| 118 | if descript.homepage then | ||
| 119 | print("Homepage: ", descript.homepage) | ||
| 120 | end | ||
| 121 | print("Installed in: ", repo) | ||
| 122 | if next(minfo.modules) then | ||
| 123 | print() | ||
| 124 | print("Modules:") | ||
| 125 | print("\t"..keys_as_string(minfo.modules, "\n\t")) | ||
| 126 | end | ||
| 127 | if next(minfo.dependencies) then | ||
| 128 | print() | ||
| 129 | print("Depends on:") | ||
| 130 | print("\t"..keys_as_string(minfo.dependencies, "\n\t")) | ||
| 131 | end | ||
| 132 | print() | ||
| 133 | end | ||
| 134 | return true | ||
| 135 | end | ||
| 136 | |||
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 164dd260..ed70b2ba 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -243,6 +243,33 @@ function starts_with(s, prefix) | |||
| 243 | return s:sub(1,#prefix) == prefix | 243 | return s:sub(1,#prefix) == prefix |
| 244 | end | 244 | end |
| 245 | 245 | ||
| 246 | -- from http://lua-users.org/wiki/SplitJoin | ||
| 247 | -- by PhilippeLhoste | ||
| 248 | function split_string(str, delim, maxNb) | ||
| 249 | -- Eliminate bad cases... | ||
| 250 | if string.find(str, delim) == nil then | ||
| 251 | return { str } | ||
| 252 | end | ||
| 253 | if maxNb == nil or maxNb < 1 then | ||
| 254 | maxNb = 0 -- No limit | ||
| 255 | end | ||
| 256 | local result = {} | ||
| 257 | local pat = "(.-)" .. delim .. "()" | ||
| 258 | local nb = 0 | ||
| 259 | local lastPos | ||
| 260 | for part, pos in string.gfind(str, pat) do | ||
| 261 | nb = nb + 1 | ||
| 262 | result[nb] = part | ||
| 263 | lastPos = pos | ||
| 264 | if nb == maxNb then break end | ||
| 265 | end | ||
| 266 | -- Handle the last field | ||
| 267 | if nb ~= maxNb then | ||
| 268 | result[nb + 1] = string.sub(str, lastPos) | ||
| 269 | end | ||
| 270 | return result | ||
| 271 | end | ||
| 272 | |||
| 246 | --[[ | 273 | --[[ |
| 247 | Author: Julio Manuel Fernandez-Diaz | 274 | Author: Julio Manuel Fernandez-Diaz |
| 248 | Date: January 12, 2007 | 275 | Date: January 12, 2007 |
