diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-12-19 16:45:03 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-01-10 16:40:40 -0200 |
commit | 9f8ab8c17a054557d4159b2c41204d8ca211c6cf (patch) | |
tree | 4a7c9e84c0cc061b7b9968c3e5aed4c49245e361 | |
parent | 31685028b3e945bc30a1e567508ce1ebc3bd5d06 (diff) | |
download | luarocks-9f8ab8c17a054557d4159b2c41204d8ca211c6cf.tar.gz luarocks-9f8ab8c17a054557d4159b2c41204d8ca211c6cf.tar.bz2 luarocks-9f8ab8c17a054557d4159b2c41204d8ca211c6cf.zip |
Factor out function for use by luarocks.doc
-rw-r--r-- | src/luarocks/show.lua | 34 |
1 files 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) | |||
66 | return dir.path(base_dir, filename) | 66 | return dir.path(base_dir, filename) |
67 | end | 67 | end |
68 | 68 | ||
69 | --- Driver function for "show" command. | 69 | function pick_installed_rock(name, version, tree) |
70 | -- @param name or nil: an existing package name. | ||
71 | -- @param version string or nil: a version may also be passed. | ||
72 | -- @return boolean: True if succeeded, nil on errors. | ||
73 | function run(...) | ||
74 | local flags, name, version = util.parse_flags(...) | ||
75 | if not name then | ||
76 | return nil, "Argument missing. "..util.see_help("show") | ||
77 | end | ||
78 | local results = {} | 70 | local results = {} |
79 | local query = search.make_query(name, version) | 71 | local query = search.make_query(name, version) |
80 | query.exact_name = true | 72 | query.exact_name = true |
81 | local tree_map = {} | 73 | local tree_map = {} |
82 | local trees = cfg.rocks_trees | 74 | local trees = cfg.rocks_trees |
83 | if flags["tree"] then | 75 | if tree then |
84 | trees = { flags["tree"] } | 76 | trees = { tree } |
85 | end | 77 | end |
86 | for _, tree in ipairs(trees) do | 78 | for _, tree in ipairs(trees) do |
87 | local rocks_dir = path.rocks_dir(tree) | 79 | local rocks_dir = path.rocks_dir(tree) |
@@ -103,8 +95,26 @@ function run(...) | |||
103 | for _, rp in ipairs(repositories) do repo_url = rp.repo end | 95 | for _, rp in ipairs(repositories) do repo_url = rp.repo end |
104 | end | 96 | end |
105 | 97 | ||
106 | |||
107 | local repo = tree_map[repo_url] | 98 | local repo = tree_map[repo_url] |
99 | return name, version, repo, repo_url | ||
100 | end | ||
101 | |||
102 | --- Driver function for "show" command. | ||
103 | -- @param name or nil: an existing package name. | ||
104 | -- @param version string or nil: a version may also be passed. | ||
105 | -- @return boolean: True if succeeded, nil on errors. | ||
106 | function run(...) | ||
107 | local flags, name, version = util.parse_flags(...) | ||
108 | if not name then | ||
109 | return nil, "Argument missing. "..util.see_help("show") | ||
110 | end | ||
111 | |||
112 | local repo, repo_url | ||
113 | name, version, repo, repo_url = pick_installed_rock(name, version, flags["tree"]) | ||
114 | if not name then | ||
115 | return nil, version | ||
116 | end | ||
117 | |||
108 | local directory = path.install_dir(name,version,repo) | 118 | local directory = path.install_dir(name,version,repo) |
109 | local rockspec_file = path.rockspec_file(name, version, repo) | 119 | local rockspec_file = path.rockspec_file(name, version, repo) |
110 | local rockspec, err = fetch.load_local_rockspec(rockspec_file) | 120 | local rockspec, err = fetch.load_local_rockspec(rockspec_file) |