daily pastebin goal
14%
SHARE
TWEET

luarocks_list.lua.diff

_dinsdale Mar 5th, 2017 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua
  2. index 8affc52..2efcfdd 100644
  3. --- a/src/luarocks/list.lua
  4. +++ b/src/luarocks/list.lua
  5. @@ -4,6 +4,9 @@
  6.  --module("luarocks.list", package.seeall)
  7.  local list = {}
  8.  package.loaded["luarocks.list"] = list
  9. +  
  10. +local flags, filter, version, query, trees
  11. +
  12.  
  13.  local search = require("luarocks.search")
  14.  local deps = require("luarocks.deps")
  15. @@ -22,7 +25,9 @@ list.help = [[
  16.  --porcelain   Produce machine-friendly output.
  17.  ]]
  18.  
  19. -local function check_outdated(trees, query)
  20. +---Searches for outdated packages in the given tree
  21. +-- @return table,table,table,string: results, trees, flags, version
  22. +local function get_outdated()
  23.     local results_installed = {}
  24.     for _, tree in ipairs(trees) do
  25.        search.manifest_search(results_installed, path.rocks_dir(tree), query)
  26. @@ -48,12 +53,14 @@ local function check_outdated(trees, query)
  27.           end
  28.        end
  29.     end
  30. -   return outdated
  31. +   return outdated, trees, flags, version
  32.  end
  33.  
  34. -local function list_outdated(trees, query, porcelain)
  35. +--- Outputs the outdated packages
  36. +-- @return true
  37. +local function print_outdated(porcelain)
  38.     util.title("Outdated rocks:", porcelain)
  39. -   local outdated = check_outdated(trees, query)
  40. +   local outdated = get_outdated()
  41.     for _, item in ipairs(outdated) do
  42.        if porcelain then
  43.           util.printout(item.name, item.installed, item.available, item.repo)
  44. @@ -69,20 +76,9 @@ end
  45.  --- Driver function for "list" command.
  46.  -- @param filter string or nil: A substring of a rock name to filter by.
  47.  -- @param version string or nil: a version may also be passed.
  48. --- @return boolean: True if succeeded, nil on errors.
  49. -function list.run(...)
  50. -   local flags, filter, version = util.parse_flags(...)
  51. -   local query = search.make_query(filter and filter:lower() or "", version)
  52. -   query.exact_name = false
  53. -   local trees = cfg.rocks_trees
  54. -   if flags["tree"] then
  55. -      trees = { flags["tree"] }
  56. -   end
  57. -  
  58. -   if flags["outdated"] then
  59. -      return list_outdated(trees, query, flags["porcelain"])
  60. -   end
  61. -  
  62. +-- @return table,table,table,string: results, trees, flags, version
  63. +local function get_results()
  64. +      
  65.     local results = {}
  66.     for _, tree in ipairs(trees) do
  67.        local ok, err, errcode = search.manifest_search(results, path.rocks_dir(tree), query)
  68. @@ -90,9 +86,46 @@ function list.run(...)
  69.           util.warning(err)
  70.        end
  71.     end
  72. -   util.title("Installed rocks:", flags["porcelain"])
  73. -   search.print_results(results, flags["porcelain"])
  74. +   return results, trees, flags, version
  75. +end
  76. +
  77. +--- Parse the arguments, create the query and get the trees.
  78. +local function parse(...)
  79. +   flags, filter, version = util.parse_flags(...)
  80. +   query = search.make_query(filter and filter:lower() or "", version)
  81. +   query.exact_name = false
  82. +   trees = cfg.rocks_trees
  83. +   if flags["tree"] then
  84. +      trees = { flags["tree"] }
  85. +   end
  86. +end
  87. +
  88. +--- Run function for "list" command. This is called by command_line  
  89. +-- when the user specifies `list`.
  90. +-- @param filter string or nil: A substring of a rock name to filter by.
  91. +-- @param version string or nil: a version may also be passed.
  92. +-- @return true
  93. +function list.run(...)
  94. +   parse(...)
  95. +   if flags["outdated"] then
  96. +      print_outdated(flags["porcelain"])
  97. +   else
  98. +      util.title("Installed rocks:", flags["porcelain"])
  99. +      search.print_results(get_results(), flags["porcelain"])
  100. +   end
  101. +  
  102.     return true
  103.  end
  104.  
  105. +-- Return the table results from the list command
  106. +-- @return table,table,table,string: results, trees, flags, version
  107. +function list.list(...)
  108. +  parse(...)
  109. +  if flags["outdated"] then
  110. +    return get_outdated()
  111. +  else
  112. +    return get_results()
  113. +  end
  114. +end
  115. +
  116.  return list
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top