aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/bin/luarocks2
-rw-r--r--src/luarocks/download.lua (renamed from src/luarocks/get_rockspec.lua)40
2 files changed, 23 insertions, 19 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks
index 2e2ac422..80b53dee 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -15,6 +15,6 @@ commands.search = require("luarocks.search")
15commands.list = require("luarocks.list") 15commands.list = require("luarocks.list")
16commands.remove = require("luarocks.remove") 16commands.remove = require("luarocks.remove")
17commands.make = require("luarocks.make") 17commands.make = require("luarocks.make")
18commands.get_rockspec = require("luarocks.get_rockspec") 18commands.download = require("luarocks.download")
19 19
20command_line.run_command(...) 20command_line.run_command(...)
diff --git a/src/luarocks/get_rockspec.lua b/src/luarocks/download.lua
index 77fb6d21..5dc393d6 100644
--- a/src/luarocks/get_rockspec.lua
+++ b/src/luarocks/download.lua
@@ -1,29 +1,28 @@
1 1
2--- Module implementing the luarocks "get_rockspec" command. 2--- Module implementing the luarocks "download" command.
3-- Download a rockspec from the repository. 3-- Download a rock from the repository.
4module("luarocks.get_rockspec", package.seeall) 4module("luarocks.download", package.seeall)
5 5
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local path = require("luarocks.path") 7local path = require("luarocks.path")
8local fetch = require("luarocks.fetch") 8local fetch = require("luarocks.fetch")
9local search = require("luarocks.search") 9local search = require("luarocks.search")
10 10
11help_summary = "Download a specific rockspec file from a rocks server." 11help_summary = "Download a specific rock file from a rocks server."
12help_arguments = "[--all] [<name> [<version>]]" 12help_arguments = "[--all] [--source] [--arch=<arch>] [<name> [<version>]]"
13 13
14help = [[ 14help = [[
15--all Download multiple rockspec files if there is more than one match. 15--all Download multiple rock files if there is more than one match.
16--source Download .src.rock if available.
17--arch=<arch> Download rock for a specific architecture.
16]] 18]]
17 19
18local function get_rockspec(rockspec_file) 20local function download(rock_file)
19 local rockspec = fetch.load_rockspec(rockspec_file, ".") 21 local rock = fetch.fetch_url(rock_file)
20 if not rockspec then 22 return rock ~= nil
21 return nil, "Failed loading rockspec "..rockspec_file
22 end
23 return true
24end 23end
25 24
26--- Driver function for the "get_rockspec" command. 25--- Driver function for the "download" command.
27-- @param name string: a rock name. 26-- @param name string: a rock name.
28-- @param version string or nil: if the name of a package is given, a 27-- @param version string or nil: if the name of a package is given, a
29-- version may also be passed. 28-- version may also be passed.
@@ -39,17 +38,22 @@ function run(...)
39 if not name then name, version = "", "" end 38 if not name then name, version = "", "" end
40 39
41 local query = search.make_query(name, version) 40 local query = search.make_query(name, version)
42 query.arch = "rockspec" 41 if flags["source"] then
42 query.arch = "src"
43 elseif flags["rockspec"] then
44 query.arch = "rockspec"
45 elseif flags["arch"] then
46 query.arch = flags["arch"]
47 end
43 local results, err 48 local results, err
44 if flags["all"] then 49 if flags["all"] then
45 if name == "" then query.exact_name = false end 50 if name == "" then query.exact_name = false end
46 results, err = search.search_repos(query) 51 results, err = search.search_repos(query)
47 print(results, err)
48 else 52 else
49 results, err = search.find_suitable_rock(query) 53 results, err = search.find_suitable_rock(query)
50 end 54 end
51 if type(results) == "string" then 55 if type(results) == "string" then
52 return get_rockspec(results) 56 return download(results)
53 elseif type(results) == "table" and next(results) then 57 elseif type(results) == "table" and next(results) then
54 if flags["all"] then 58 if flags["all"] then
55 local all_ok = true 59 local all_ok = true
@@ -58,7 +62,7 @@ function run(...)
58 for version, versions in pairs(result) do 62 for version, versions in pairs(result) do
59 for _,items in pairs(versions) do 63 for _,items in pairs(versions) do
60 local filename = path.make_url(items.repo, name, version, items.arch) 64 local filename = path.make_url(items.repo, name, version, items.arch)
61 local ok, err = get_rockspec(filename) 65 local ok, err = download(filename)
62 if not ok then 66 if not ok then
63 all_ok = false 67 all_ok = false
64 any_err = any_err .. "\n" .. err 68 any_err = any_err .. "\n" .. err
@@ -76,6 +80,6 @@ function run(...)
76 return nil, "Please narrow your query or use --all." 80 return nil, "Please narrow your query or use --all."
77 end 81 end
78 else 82 else
79 return nil, "Could not find a result named "..name.."." 83 return nil, "Could not find a result named "..name..(version and " "..version or "").."."
80 end 84 end
81end 85end