--- Module implementing the LuaRocks "show" command. -- Shows information about an installed rock. module("luarocks.show", package.seeall) local search = require("luarocks.search") local cfg = require("luarocks.cfg") local util = require("luarocks.util") local path = require("luarocks.path") local dir = require("luarocks.dir") local deps = require("luarocks.deps") local fetch = require("luarocks.fetch") local manif = require("luarocks.manif") help_summary = "Shows information about an installed rock." help = [[ is an existing package name. Without any flags, show all module information. With these flags, return only the desired information: --home home page of project --modules all modules provided by this package as used by require() --deps packages this package depends on --rockspec the full path of the rockspec file --mversion the package version ]] local function keys_as_string(t) return table.concat(util.keys(t)," ") end local function trim(s) return (s:gsub('^%s*',''):gsub('\n%s+','\n')) end --- Driver function for "show" command. -- @param name or nil: an existing package name. -- @param version string or nil: a version may also be passed. -- @return boolean: True if succeeded, nil on errors. function run(...) local flags, name, version = util.parse_flags(...) local results = {} local query = search.make_query(name, version) query.exact_name = true local tree_map = {} for _, tree in ipairs(cfg.rocks_trees) do local rocks_dir = path.rocks_dir(tree) tree_map[rocks_dir] = tree search.manifest_search(results, rocks_dir, query) end if not next(results) then -- return nil,"cannot find package "..name.."\nUse 'list' to find installed rocks" end local version,repo_url local package, versions = util.sortedpairs(results)() --question: what do we do about multiple versions? This should --give us the latest version on the last repo (which is usually the global one) for vs, repos in util.sortedpairs(versions, deps.compare_versions) do version = vs for _, rp in ipairs(repos) do repo_url = rp.repo end end local repo = tree_map[repo_url] local directory = path.install_dir(name,version,repo) local rockspec_file = path.rockspec_file(name, version, repo) local rockspec, err = fetch.load_local_rockspec(rockspec_file) if not rockspec then return nil,err end local descript = rockspec.description local manifest, err = manif.load_manifest(repo_url) if not manifest then return nil,err end local minfo = manifest.repository[name][version][1] local modstring = keys_as_string(minfo.modules) local deps = keys_as_string(minfo.dependencies) if flags['dir'] then print(directory) elseif flags['home'] then print(descript.homepage) elseif flags['modules'] then print(modstring) elseif flags['deps'] then print(deps) elseif flags['rockspec'] then print(rockspec_file) elseif flags['mversion'] then print(version) else print('version:',rockspec.version) print('summary:',descript.summary) print('detailed:\n'..trim(descript.detailed)) print('homepage:',descript.homepage) print('directory:',directory) print('modules:',modstring) if #deps > 0 then print('depends on:',deps) end end return true end