diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2012-10-17 11:00:33 -0700 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2012-10-17 11:00:33 -0700 |
commit | 9b254a77abd872ba707027059eb53a51b60f231a (patch) | |
tree | d707eef7f7958b997dd524ab49ff5d89a06ff2c7 | |
parent | 5c17b07c4d70d459d512cb10db233bbf847a44c1 (diff) | |
parent | b2d24d390bdfc6217211e182dbe4a0f7c6242e36 (diff) | |
download | luarocks-9b254a77abd872ba707027059eb53a51b60f231a.tar.gz luarocks-9b254a77abd872ba707027059eb53a51b60f231a.tar.bz2 luarocks-9b254a77abd872ba707027059eb53a51b60f231a.zip |
Merge pull request #108 from dvv/master
introduce --porcelain cmdline flag for #21
-rw-r--r-- | src/luarocks/list.lua | 16 | ||||
-rw-r--r-- | src/luarocks/search.lua | 62 |
2 files changed, 48 insertions, 30 deletions
diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index 1943f932..f9aa5fe1 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua | |||
@@ -26,10 +26,16 @@ function run(...) | |||
26 | for _, tree in ipairs(cfg.rocks_trees) do | 26 | for _, tree in ipairs(cfg.rocks_trees) do |
27 | search.manifest_search(results, path.rocks_dir(tree), query) | 27 | search.manifest_search(results, path.rocks_dir(tree), query) |
28 | end | 28 | end |
29 | util.printout() | 29 | -- machine-readable output |
30 | util.printout("Installed rocks:") | 30 | if flags["porcelain"] then |
31 | util.printout("----------------") | 31 | search.print_results(results, true) |
32 | util.printout() | 32 | -- pretty human-readable output |
33 | search.print_results(results, false) | 33 | else |
34 | util.printout() | ||
35 | util.printout("Installed rocks:") | ||
36 | util.printout("----------------") | ||
37 | util.printout() | ||
38 | search.print_results(results) | ||
39 | end | ||
34 | return true | 40 | return true |
35 | end | 41 | end |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 692004ae..eeb9c20c 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -282,25 +282,30 @@ end | |||
282 | --- Print a list of rocks/rockspecs on standard output. | 282 | --- Print a list of rocks/rockspecs on standard output. |
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 porcelain boolean or nil: A flag to force machine-friendly output. |
286 | function print_results(results, show_repo) | 286 | function print_results(results, porcelain) |
287 | assert(type(results) == "table") | 287 | assert(type(results) == "table") |
288 | assert(type(show_repo) == "boolean" or not show_repo) | 288 | assert(type(porcelain) == "boolean" or not porcelain) |
289 | -- Force display of repo location for the time being | ||
290 | show_repo = true -- show_repo == nil and true or show_repo | ||
291 | 289 | ||
292 | for package, versions in util.sortedpairs(results) do | 290 | for package, versions in util.sortedpairs(results) do |
293 | util.printout(package) | 291 | if not porcelain then |
294 | for version, repositories in util.sortedpairs(versions, deps.compare_versions) do | 292 | util.printout(package) |
295 | if show_repo then | 293 | end |
296 | for _, repo in ipairs(repositories) do | 294 | for version, repos in util.sortedpairs(versions, deps.compare_versions) do |
297 | util.printout(" "..version.." ("..repo.arch..") - "..repo.repo) | 295 | for _, repo in ipairs(repos) do |
296 | if porcelain then | ||
297 | util.printout(package, version, repo.arch, repo.repo) | ||
298 | --for k, v in pairs(repo) do print(k, v) end | ||
299 | else | ||
300 | util.printout( | ||
301 | " "..version.." ("..repo.arch..") - "..repo.repo | ||
302 | ) | ||
298 | end | 303 | end |
299 | else | ||
300 | util.printout(" "..version) | ||
301 | end | 304 | end |
302 | end | 305 | end |
303 | util.printout() | 306 | if not porcelain then |
307 | util.printout() | ||
308 | end | ||
304 | end | 309 | end |
305 | end | 310 | end |
306 | 311 | ||
@@ -369,22 +374,29 @@ function run(...) | |||
369 | local query = make_query(name:lower(), version) | 374 | local query = make_query(name:lower(), version) |
370 | query.exact_name = false | 375 | query.exact_name = false |
371 | local results, err = search_repos(query) | 376 | local results, err = search_repos(query) |
372 | util.printout() | 377 | -- N.B. --porcelain forces machine-readable output |
373 | util.printout("Search results:") | 378 | if not flags["porcelain"] then |
374 | util.printout("===============") | 379 | util.printout() |
375 | util.printout() | 380 | util.printout("Search results:") |
381 | util.printout("===============") | ||
382 | util.printout() | ||
383 | end | ||
376 | local sources, binaries = split_source_and_binary_results(results) | 384 | local sources, binaries = split_source_and_binary_results(results) |
377 | if next(sources) and not flags["binary"] then | 385 | if next(sources) and not flags["binary"] then |
378 | util.printout("Rockspecs and source rocks:") | 386 | if not flags["porcelain"] then |
379 | util.printout("---------------------------") | 387 | util.printout("Rockspecs and source rocks:") |
380 | util.printout() | 388 | util.printout("---------------------------") |
381 | print_results(sources, true) | 389 | util.printout() |
390 | end | ||
391 | print_results(sources, flags["porcelain"]) | ||
382 | end | 392 | end |
383 | if next(binaries) and not flags["source"] then | 393 | if next(binaries) and not flags["source"] then |
384 | util.printout("Binary and pure-Lua rocks:") | 394 | if not flags["porcelain"] then |
385 | util.printout("--------------------------") | 395 | util.printout("Binary and pure-Lua rocks:") |
386 | util.printout() | 396 | util.printout("--------------------------") |
387 | print_results(binaries, true) | 397 | util.printout() |
398 | end | ||
399 | print_results(binaries, flags["porcelain"]) | ||
388 | end | 400 | end |
389 | return true | 401 | return true |
390 | end | 402 | end |