diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-24 19:15:15 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 15:51:36 -0300 |
commit | 9add0ca679b6bf273fe7aad7fa8fbc03119649f6 (patch) | |
tree | bc28d310286150dd17cbdfc50f8fb5d67ed22fde /src | |
parent | 1c2fe8bad11a343c63e658cf43dcbf30c930eec5 (diff) | |
download | luarocks-9add0ca679b6bf273fe7aad7fa8fbc03119649f6.tar.gz luarocks-9add0ca679b6bf273fe7aad7fa8fbc03119649f6.tar.bz2 luarocks-9add0ca679b6bf273fe7aad7fa8fbc03119649f6.zip |
show: add --porcelain and --rock-license options
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd/show.lua | 203 | ||||
-rw-r--r-- | src/luarocks/util.lua | 1 |
2 files changed, 130 insertions, 74 deletions
diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index ffac440b..b6242cbc 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua | |||
@@ -29,6 +29,59 @@ With these flags, return only the desired information: | |||
29 | --rock-dir data directory of the installed rock | 29 | --rock-dir data directory of the installed rock |
30 | ]] | 30 | ]] |
31 | 31 | ||
32 | |||
33 | local friendly_template = [[ | ||
34 | : | ||
35 | ?namespace:${namespace}/${package} ${version} - ${summary} | ||
36 | !namespace:${package} ${version} - ${summary} | ||
37 | : | ||
38 | *detailed :${detailed} | ||
39 | ?detailed : | ||
40 | ?license :License: \t${license} | ||
41 | ?homepage :Homepage: \t${homepage} | ||
42 | ?issues :Issues: \t${issues} | ||
43 | ?labels :Labels: \t${labels} | ||
44 | ?location :Installed in: \t${location} | ||
45 | ?commands : | ||
46 | ?commands :Commands: | ||
47 | *commands :\t${name} (${repo}) | ||
48 | ?modules : | ||
49 | ?modules :Modules: | ||
50 | *modules :\t${name} (${repo}) | ||
51 | ?bdeps : | ||
52 | ?bdeps :Has build dependency on: | ||
53 | *bdeps :\t${name} (${label}) | ||
54 | ?tdeps : | ||
55 | ?tdeps :Tests depend on: | ||
56 | *tdeps :\t${name} (${label}) | ||
57 | ?deps : | ||
58 | ?deps :Depends on: | ||
59 | *deps :\t${name} (${label}) | ||
60 | ?ideps : | ||
61 | ?ideps :Indirectly pulling: | ||
62 | *ideps :\t${name} (${label}) | ||
63 | : | ||
64 | ]] | ||
65 | |||
66 | local porcelain_template = [[ | ||
67 | ?namespace:namespace\t${namespace} | ||
68 | ?package :package\t${package} | ||
69 | ?version :version\t${version} | ||
70 | ?summary :summary\t${summary} | ||
71 | *detailed :detailed\t${detailed} | ||
72 | ?license :license\t${license} | ||
73 | ?homepage :homepage\t${homepage} | ||
74 | ?issues :issues\t${issues} | ||
75 | ?labels :labels\t${labels} | ||
76 | ?location :location\t${location} | ||
77 | *commands :command\t${name}\t${repo} | ||
78 | *modules :module\t${name}\t${repo} | ||
79 | *bdeps :build_dependency\t${name}\t${label} | ||
80 | *tdeps :test_dependency\t${name}\t${label} | ||
81 | *deps :dependency\t${name}\t${label} | ||
82 | *ideps :indirect_dependency\t${name}\t${label} | ||
83 | ]] | ||
84 | |||
32 | local function keys_as_string(t, sep) | 85 | local function keys_as_string(t, sep) |
33 | local keys = util.keys(t) | 86 | local keys = util.keys(t) |
34 | table.sort(keys) | 87 | table.sort(keys) |
@@ -66,13 +119,82 @@ local function installed_rock_label(dep, tree) | |||
66 | else | 119 | else |
67 | installed, version = search.pick_installed_rock(dep, tree) | 120 | installed, version = search.pick_installed_rock(dep, tree) |
68 | end | 121 | end |
69 | return installed and "(using "..version..")" or "(missing)" | 122 | return installed and "using "..version or "missing" |
123 | end | ||
124 | |||
125 | local function render(template, data) | ||
126 | local out = {} | ||
127 | for cmd, var, line in template:gmatch("(.)([a-z]*)%s*:([^\n]*)\n") do | ||
128 | line = line:gsub("\\t", "\t") | ||
129 | local d = data[var] | ||
130 | if cmd == " " then | ||
131 | table.insert(out, line) | ||
132 | elseif cmd == "?" or cmd == "*" or cmd == "!" then | ||
133 | if (cmd == "!" and d == nil) | ||
134 | or (cmd ~= "!" and (type(d) == "string" | ||
135 | or (type(d) == "table" and next(d)))) then | ||
136 | local n = cmd == "*" and #d or 1 | ||
137 | for i = 1, n do | ||
138 | local tbl = cmd == "*" and d[i] or data | ||
139 | table.insert(out, (line:gsub("${([a-z]+)}", tbl))) | ||
140 | end | ||
141 | end | ||
142 | end | ||
143 | end | ||
144 | return table.concat(out, "\n") | ||
70 | end | 145 | end |
71 | 146 | ||
72 | local function print_items(name, version, item_set, item_type, repo) | 147 | local function files_to_list(name, version, item_set, item_type, repo) |
148 | local ret = {} | ||
73 | for item_name in util.sortedpairs(item_set) do | 149 | for item_name in util.sortedpairs(item_set) do |
74 | util.printout("\t"..item_name.." ("..repos.which(name, version, item_type, item_name, repo)..")") | 150 | table.insert(ret, { name = item_name, repo = repos.which(name, version, item_type, item_name, repo) }) |
75 | end | 151 | end |
152 | return ret | ||
153 | end | ||
154 | |||
155 | local function deps_to_list(dependencies, tree) | ||
156 | local ret = {} | ||
157 | for _, dep in ipairs(dependencies or {}) do | ||
158 | table.insert(ret, { name = tostring(dep), label = installed_rock_label(dep, tree) }) | ||
159 | end | ||
160 | return ret | ||
161 | end | ||
162 | |||
163 | local function indirect_deps(mdeps, rdeps, tree) | ||
164 | local ret = {} | ||
165 | local direct_deps = {} | ||
166 | for _, dep in ipairs(rdeps) do | ||
167 | direct_deps[dep] = true | ||
168 | end | ||
169 | for dep_name in util.sortedpairs(mdeps or {}) do | ||
170 | if not direct_deps[dep_name] then | ||
171 | table.insert(ret, { name = tostring(dep_name), label = installed_rock_label(queries.new(dep_name), tree) }) | ||
172 | end | ||
173 | end | ||
174 | return ret | ||
175 | end | ||
176 | |||
177 | local function show_rock(template, namespace, name, version, rockspec, repo, minfo, tree) | ||
178 | local desc = rockspec.description | ||
179 | local data = { | ||
180 | namespace = namespace, | ||
181 | package = rockspec.package, | ||
182 | version = rockspec.version, | ||
183 | summary = desc.summary or "", | ||
184 | detailed = desc.detailed and util.split_string(format_text(desc.detailed), "\n"), | ||
185 | license = desc.license, | ||
186 | homepage = desc.homepage, | ||
187 | issues = desc.issues_url, | ||
188 | labels = desc.labels and table.concat(desc.labels, ", "), | ||
189 | location = path.rocks_tree_to_string(repo), | ||
190 | commands = files_to_list(name, version, minfo.commands, "command", repo), | ||
191 | modules = files_to_list(name, version, minfo.modules, "module", repo), | ||
192 | bdeps = deps_to_list(rockspec.build_dependencies, tree), | ||
193 | tdeps = deps_to_list(rockspec.test_dependencies, tree), | ||
194 | deps = deps_to_list(rockspec.dependencies, tree), | ||
195 | ideps = indirect_deps(minfo.dependencies, rockspec.dependencies, tree), | ||
196 | } | ||
197 | util.printout(render(template, data)) | ||
76 | end | 198 | end |
77 | 199 | ||
78 | --- Driver function for "show" command. | 200 | --- Driver function for "show" command. |
@@ -108,6 +230,7 @@ function show.command(flags, name, version) | |||
108 | elseif flags["rock-namespace"] then util.printout(namespace) | 230 | elseif flags["rock-namespace"] then util.printout(namespace) |
109 | elseif flags["rock-dir"] then util.printout(directory) | 231 | elseif flags["rock-dir"] then util.printout(directory) |
110 | elseif flags["home"] then util.printout(descript.homepage) | 232 | elseif flags["home"] then util.printout(descript.homepage) |
233 | elseif flags["rock-license"] then util.printout(descript.license) | ||
111 | elseif flags["issues"] then util.printout(descript.issues_url) | 234 | elseif flags["issues"] then util.printout(descript.issues_url) |
112 | elseif flags["labels"] then util.printout(descript.labels and table.concat(descript.labels, "\n")) | 235 | elseif flags["labels"] then util.printout(descript.labels and table.concat(descript.labels, "\n")) |
113 | elseif flags["modules"] then util.printout(keys_as_string(minfo.modules, "\n")) | 236 | elseif flags["modules"] then util.printout(keys_as_string(minfo.modules, "\n")) |
@@ -125,78 +248,10 @@ function show.command(flags, name, version) | |||
125 | end | 248 | end |
126 | elseif flags["rockspec"] then util.printout(rockspec_file) | 249 | elseif flags["rockspec"] then util.printout(rockspec_file) |
127 | elseif flags["mversion"] then util.printout(version) | 250 | elseif flags["mversion"] then util.printout(version) |
251 | elseif flags["porcelain"] then | ||
252 | show_rock(porcelain_template, namespace, name, version, rockspec, repo, minfo, flags["tree"]) | ||
128 | else | 253 | else |
129 | util.printout() | 254 | show_rock(friendly_template, namespace, name, version, rockspec, repo, minfo, flags["tree"]) |
130 | util.printout((namespace and namespace .."/" or "") .. rockspec.package.." "..rockspec.version.." - "..(descript.summary or "")) | ||
131 | util.printout() | ||
132 | if descript.detailed then | ||
133 | util.printout(format_text(descript.detailed)) | ||
134 | util.printout() | ||
135 | end | ||
136 | if descript.license then | ||
137 | util.printout("License: ", descript.license) | ||
138 | end | ||
139 | if descript.homepage then | ||
140 | util.printout("Homepage: ", descript.homepage) | ||
141 | end | ||
142 | if descript.issues_url then | ||
143 | util.printout("Issues: ", descript.issues_url) | ||
144 | end | ||
145 | if descript.labels then | ||
146 | util.printout("Labels: ", table.concat(descript.labels, ", ")) | ||
147 | end | ||
148 | util.printout("Installed in: ", path.rocks_tree_to_string(repo)) | ||
149 | |||
150 | if next(minfo.commands) then | ||
151 | util.printout() | ||
152 | util.printout("Commands: ") | ||
153 | print_items(name, version, minfo.commands, "command", repo) | ||
154 | end | ||
155 | |||
156 | if next(minfo.modules) then | ||
157 | util.printout() | ||
158 | util.printout("Modules: ") | ||
159 | print_items(name, version, minfo.modules, "module", repo) | ||
160 | end | ||
161 | |||
162 | if #rockspec.build_dependencies > 0 then | ||
163 | util.printout() | ||
164 | util.printout("Has build dependency on:") | ||
165 | for _, dep in ipairs(rockspec.build_dependencies) do | ||
166 | util.printout("\t"..tostring(dep).." "..installed_rock_label(dep, flags["tree"])) | ||
167 | end | ||
168 | end | ||
169 | |||
170 | if #rockspec.test_dependencies > 0 then | ||
171 | util.printout() | ||
172 | util.printout("Tests depend on:") | ||
173 | for _, dep in ipairs(rockspec.test_dependencies) do | ||
174 | util.printout("\t"..tostring(dep).." "..installed_rock_label(dep, flags["tree"])) | ||
175 | end | ||
176 | end | ||
177 | |||
178 | local direct_deps = {} | ||
179 | if #rockspec.dependencies > 0 then | ||
180 | util.printout() | ||
181 | util.printout("Depends on:") | ||
182 | for _, dep in ipairs(rockspec.dependencies) do | ||
183 | direct_deps[dep.name] = true | ||
184 | util.printout("\t"..tostring(dep).." "..installed_rock_label(dep, flags["tree"])) | ||
185 | end | ||
186 | end | ||
187 | local has_indirect_deps | ||
188 | for dep_name in util.sortedpairs(minfo.dependencies or {}) do | ||
189 | if not direct_deps[dep_name] then | ||
190 | if not has_indirect_deps then | ||
191 | util.printout() | ||
192 | util.printout("Indirectly pulling:") | ||
193 | has_indirect_deps = true | ||
194 | end | ||
195 | |||
196 | util.printout("\t"..tostring(dep_name).." "..installed_rock_label(queries.new(dep_name), flags["tree"])) | ||
197 | end | ||
198 | end | ||
199 | util.printout() | ||
200 | end | 255 | end |
201 | return true | 256 | return true |
202 | end | 257 | end |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index fd2b7b42..bb81d61b 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -138,6 +138,7 @@ local supported_flags = { | |||
138 | ["project-tree"] = "<tree>", | 138 | ["project-tree"] = "<tree>", |
139 | ["quick"] = true, | 139 | ["quick"] = true, |
140 | ["rock-dir"] = true, | 140 | ["rock-dir"] = true, |
141 | ["rock-license"] = true, | ||
141 | ["rock-namespace"] = true, | 142 | ["rock-namespace"] = true, |
142 | ["rock-tree"] = true, | 143 | ["rock-tree"] = true, |
143 | ["rock-trees"] = true, | 144 | ["rock-trees"] = true, |