From 9f8ab8c17a054557d4159b2c41204d8ca211c6cf Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:45:03 -0200 Subject: Factor out function for use by luarocks.doc --- src/luarocks/show.lua | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 536085a7..2e039dd4 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -66,22 +66,14 @@ local function module_name(mod, filename, name, version, repo, manifest) return dir.path(base_dir, filename) 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(...) - if not name then - return nil, "Argument missing. "..util.see_help("show") - end +function pick_installed_rock(name, version, tree) local results = {} local query = search.make_query(name, version) query.exact_name = true local tree_map = {} local trees = cfg.rocks_trees - if flags["tree"] then - trees = { flags["tree"] } + if tree then + trees = { tree } end for _, tree in ipairs(trees) do local rocks_dir = path.rocks_dir(tree) @@ -103,8 +95,26 @@ function run(...) for _, rp in ipairs(repositories) do repo_url = rp.repo end end - local repo = tree_map[repo_url] + return name, version, repo, repo_url +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(...) + if not name then + return nil, "Argument missing. "..util.see_help("show") + end + + local repo, repo_url + name, version, repo, repo_url = pick_installed_rock(name, version, flags["tree"]) + if not name then + return nil, version + end + 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) -- cgit v1.2.3-55-g6feb