aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--spec/config_spec.lua3
-rwxr-xr-xsrc/bin/luarocks38
-rwxr-xr-xsrc/bin/luarocks-admin10
-rw-r--r--src/luarocks/admin/cmd/add.lua (renamed from src/luarocks/admin/add.lua)0
-rw-r--r--src/luarocks/admin/cmd/make_manifest.lua (renamed from src/luarocks/admin/make_manifest.lua)0
-rw-r--r--src/luarocks/admin/cmd/refresh_cache.lua (renamed from src/luarocks/admin/refresh_cache.lua)0
-rw-r--r--src/luarocks/admin/cmd/remove.lua (renamed from src/luarocks/admin/remove.lua)0
-rw-r--r--src/luarocks/build.lua111
-rw-r--r--src/luarocks/cmd/build.lua118
-rw-r--r--src/luarocks/cmd/config_cmd.lua (renamed from src/luarocks/config_cmd.lua)0
-rw-r--r--src/luarocks/cmd/doc.lua (renamed from src/luarocks/doc.lua)0
-rw-r--r--src/luarocks/cmd/download.lua45
-rw-r--r--src/luarocks/cmd/help.lua (renamed from src/luarocks/help.lua)0
-rw-r--r--src/luarocks/cmd/install.lua (renamed from src/luarocks/install.lua)4
-rw-r--r--src/luarocks/cmd/lint.lua (renamed from src/luarocks/lint.lua)0
-rw-r--r--src/luarocks/cmd/list.lua (renamed from src/luarocks/list.lua)0
-rw-r--r--src/luarocks/cmd/make.lua (renamed from src/luarocks/make.lua)0
-rw-r--r--src/luarocks/cmd/new_version.lua (renamed from src/luarocks/new_version.lua)0
-rw-r--r--src/luarocks/cmd/pack.lua45
-rw-r--r--src/luarocks/cmd/path_cmd.lua (renamed from src/luarocks/path_cmd.lua)0
-rw-r--r--src/luarocks/cmd/purge.lua (renamed from src/luarocks/purge.lua)0
-rw-r--r--src/luarocks/cmd/remove.lua59
-rw-r--r--src/luarocks/cmd/search.lua74
-rw-r--r--src/luarocks/cmd/show.lua (renamed from src/luarocks/show.lua)0
-rw-r--r--src/luarocks/cmd/unpack.lua (renamed from src/luarocks/unpack.lua)0
-rw-r--r--src/luarocks/cmd/upload.lua (renamed from src/luarocks/upload.lua)0
-rw-r--r--src/luarocks/cmd/write_rockspec.lua (renamed from src/luarocks/write_rockspec.lua)0
-rw-r--r--src/luarocks/deps.lua2
-rw-r--r--src/luarocks/download.lua41
-rw-r--r--src/luarocks/pack.lua43
-rw-r--r--src/luarocks/remove.lua50
-rw-r--r--src/luarocks/search.lua72
32 files changed, 377 insertions, 338 deletions
diff --git a/spec/config_spec.lua b/spec/config_spec.lua
index 4a7f4aea..cdb5ccc4 100644
--- a/spec/config_spec.lua
+++ b/spec/config_spec.lua
@@ -57,7 +57,8 @@ describe("LuaRocks config tests #blackbox #b_config", function()
57 end) 57 end)
58 58
59 it("LuaRocks config missing user config", function() 59 it("LuaRocks config missing user config", function()
60 assert.is_false(run.luarocks_bool("config --user-config", {LUAROCKS_CONFIG = "missing_file.lua"})) 60 local output = run.luarocks("config --user-config", {LUAROCKS_CONFIG = "missing_file.lua"})
61 assert.truthy(output:match("Warning"))
61 end) 62 end)
62 end) 63 end)
63 64
diff --git a/src/bin/luarocks b/src/bin/luarocks
index 21f17da9..88a1d1ca 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -9,25 +9,25 @@ local command_line = require("luarocks.command_line")
9program_description = "LuaRocks main command-line interface" 9program_description = "LuaRocks main command-line interface"
10 10
11commands = { 11commands = {
12 help = "luarocks.help", 12 help = "luarocks.cmd.help",
13 pack = "luarocks.pack", 13 pack = "luarocks.cmd.pack",
14 unpack = "luarocks.unpack", 14 unpack = "luarocks.cmd.unpack",
15 build = "luarocks.build", 15 build = "luarocks.cmd.build",
16 install = "luarocks.install", 16 install = "luarocks.cmd.install",
17 search = "luarocks.search", 17 search = "luarocks.cmd.search",
18 list = "luarocks.list", 18 list = "luarocks.cmd.list",
19 remove = "luarocks.remove", 19 remove = "luarocks.cmd.remove",
20 make = "luarocks.make", 20 make = "luarocks.cmd.make",
21 download = "luarocks.download", 21 download = "luarocks.cmd.download",
22 path = "luarocks.path_cmd", 22 path = "luarocks.cmd.path",
23 show = "luarocks.show", 23 show = "luarocks.cmd.show",
24 new_version = "luarocks.new_version", 24 new_version = "luarocks.cmd.new_version",
25 lint = "luarocks.lint", 25 lint = "luarocks.cmd.lint",
26 write_rockspec = "luarocks.write_rockspec", 26 write_rockspec = "luarocks.cmd.write_rockspec",
27 purge = "luarocks.purge", 27 purge = "luarocks.cmd.purge",
28 doc = "luarocks.doc", 28 doc = "luarocks.cmd.doc",
29 upload = "luarocks.upload", 29 upload = "luarocks.cmd.upload",
30 config = "luarocks.config_cmd", 30 config = "luarocks.cmd.config",
31} 31}
32 32
33command_line.run_command(...) 33command_line.run_command(...)
diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin
index 660c0a70..5db24640 100755
--- a/src/bin/luarocks-admin
+++ b/src/bin/luarocks-admin
@@ -9,11 +9,11 @@ local command_line = require("luarocks.command_line")
9program_description = "LuaRocks repository administration interface" 9program_description = "LuaRocks repository administration interface"
10 10
11commands = { 11commands = {
12 help = "luarocks.help", 12 help = "luarocks.cmd.help",
13 make_manifest = "luarocks.admin.make_manifest", 13 make_manifest = "luarocks.admin.cmd.make_manifest",
14 add = "luarocks.admin.add", 14 add = "luarocks.admin.cmd.add",
15 remove = "luarocks.admin.remove", 15 remove = "luarocks.admin.cmd.remove",
16 refresh_cache = "luarocks.admin.refresh_cache", 16 refresh_cache = "luarocks.admin.cmd.refresh_cache",
17} 17}
18 18
19command_line.run_command(...) 19command_line.run_command(...)
diff --git a/src/luarocks/admin/add.lua b/src/luarocks/admin/cmd/add.lua
index daf46c1d..daf46c1d 100644
--- a/src/luarocks/admin/add.lua
+++ b/src/luarocks/admin/cmd/add.lua
diff --git a/src/luarocks/admin/make_manifest.lua b/src/luarocks/admin/cmd/make_manifest.lua
index 57851942..57851942 100644
--- a/src/luarocks/admin/make_manifest.lua
+++ b/src/luarocks/admin/cmd/make_manifest.lua
diff --git a/src/luarocks/admin/refresh_cache.lua b/src/luarocks/admin/cmd/refresh_cache.lua
index 947dbfb0..947dbfb0 100644
--- a/src/luarocks/admin/refresh_cache.lua
+++ b/src/luarocks/admin/cmd/refresh_cache.lua
diff --git a/src/luarocks/admin/remove.lua b/src/luarocks/admin/cmd/remove.lua
index 763a166f..763a166f 100644
--- a/src/luarocks/admin/remove.lua
+++ b/src/luarocks/admin/cmd/remove.lua
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index f3b054d2..ceaa20dd 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -1,43 +1,15 @@
1 1
2--- Module implementing the LuaRocks "build" command.
3-- Builds a rock, compiling its C parts if any.
4local build = {} 2local build = {}
5 3
6local pack = require("luarocks.pack")
7local path = require("luarocks.path") 4local path = require("luarocks.path")
8local util = require("luarocks.util") 5local util = require("luarocks.util")
9local repos = require("luarocks.repos")
10local fetch = require("luarocks.fetch") 6local fetch = require("luarocks.fetch")
11local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
12local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
13local deps = require("luarocks.deps") 9local deps = require("luarocks.deps")
14local writer = require("luarocks.manif.writer")
15local remove = require("luarocks.remove")
16local cfg = require("luarocks.core.cfg") 10local cfg = require("luarocks.core.cfg")
17 11local repos = require("luarocks.repos")
18build.help_summary = "Build/compile a rock." 12local writer = require("luarocks.manif.writer")
19build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}"
20build.help = [[
21Build and install a rock, compiling its C parts if any.
22Argument may be a rockspec file, a source rock file
23or the name of a rock to be fetched from a repository.
24
25--pack-binary-rock Do not install rock. Instead, produce a .rock file
26 with the contents of compilation in the current
27 directory.
28
29--keep Do not remove previously installed versions of the
30 rock after building a new one. This behavior can
31 be made permanent by setting keep_other_versions=true
32 in the configuration file.
33
34--branch=<name> Override the `source.branch` field in the loaded
35 rockspec. Allows to specify a different branch to
36 fetch. Particularly for SCM rocks.
37
38--only-deps Installs only the dependencies of the rock.
39
40]]..util.deps_mode_help()
41 13
42--- Install files to a given location. 14--- Install files to a given location.
43-- Takes a table where the array part is a list of filenames to be copied. 15-- Takes a table where the array part is a list of filenames to be copied.
@@ -361,83 +333,4 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m
361 return name, version 333 return name, version
362end 334end
363 335
364--- Build and install a rock.
365-- @param rock_file string: local or remote filename of a rock.
366-- @param need_to_fetch boolean: true if sources need to be fetched,
367-- false if the rockspec was obtained from inside a source rock.
368-- @param deps_mode: string: Which trees to check dependencies for:
369-- "one" for the current default tree, "all" for all trees,
370-- "order" for all trees with priority >= the current default, "none" for no trees.
371-- @param build_only_deps boolean: true to build the listed dependencies only.
372-- @return boolean or (nil, string, [string]): True if build was successful,
373-- or false and an error message and an optional error code.
374function build.build_rock(rock_file, need_to_fetch, deps_mode, build_only_deps)
375 assert(type(rock_file) == "string")
376 assert(type(need_to_fetch) == "boolean")
377
378 local ok, err, errcode
379 local unpack_dir
380 unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file)
381 if not unpack_dir then
382 return nil, err, errcode
383 end
384 local rockspec_file = path.rockspec_name_from_rock(rock_file)
385 ok, err = fs.change_dir(unpack_dir)
386 if not ok then return nil, err end
387 ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode, build_only_deps)
388 fs.pop_dir()
389 return ok, err, errcode
390end
391
392local function do_build(name, version, deps_mode, build_only_deps)
393 if name:match("%.rockspec$") then
394 return build.build_rockspec(name, true, false, deps_mode, build_only_deps)
395 elseif name:match("%.src%.rock$") then
396 return build.build_rock(name, false, deps_mode, build_only_deps)
397 elseif name:match("%.all%.rock$") then
398 local install = require("luarocks.install")
399 local install_fun = build_only_deps and install.install_binary_rock_deps or install.install_binary_rock
400 return install_fun(name, deps_mode)
401 elseif name:match("%.rock$") then
402 return build.build_rock(name, true, deps_mode, build_only_deps)
403 elseif not name:match(dir.separator) then
404 local search = require("luarocks.search")
405 return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps)
406 end
407 return nil, "Don't know what to do with "..name
408end
409
410--- Driver function for "build" command.
411-- @param name string: A local or remote rockspec or rock file.
412-- If a package name is given, forwards the request to "search" and,
413-- if returned a result, installs the matching rock.
414-- @param version string: When passing a package name, a version number may
415-- also be given.
416-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
417-- error message otherwise. exitcode is optionally returned.
418function build.command(flags, name, version)
419 if type(name) ~= "string" then
420 return nil, "Argument missing. "..util.see_help("build")
421 end
422 assert(type(version) == "string" or not version)
423
424 if flags["pack-binary-rock"] then
425 return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags))
426 else
427 local ok, err = fs.check_command_permissions(flags)
428 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
429 ok, err = do_build(name, version, deps.get_deps_mode(flags), flags["only-deps"])
430 if not ok then return nil, err end
431 name, version = ok, err
432 if flags["only-deps"] then
433 return name, version
434 end
435 if (not flags["keep"]) and not cfg.keep_other_versions then
436 local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"])
437 if not ok then util.printerr(err) end
438 end
439 return name, version
440 end
441end
442
443return build 336return build
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua
new file mode 100644
index 00000000..d050e6a3
--- /dev/null
+++ b/src/luarocks/cmd/build.lua
@@ -0,0 +1,118 @@
1
2--- Module implementing the LuaRocks "build" command.
3-- Builds a rock, compiling its C parts if any.
4local cmd_build = {}
5
6local pack = require("luarocks.pack")
7local path = require("luarocks.path")
8local util = require("luarocks.util")
9local fetch = require("luarocks.fetch")
10local fs = require("luarocks.fs")
11local dir = require("luarocks.dir")
12local deps = require("luarocks.deps")
13local remove = require("luarocks.remove")
14local cfg = require("luarocks.core.cfg")
15local build = require("luarocks.build")
16
17cmd_build.help_summary = "build/compile a rock."
18cmd_build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}"
19cmd_build.help = [[
20Build and install a rock, compiling its C parts if any.
21Argument may be a rockspec file, a source rock file
22or the name of a rock to be fetched from a repository.
23
24--pack-binary-rock Do not install rock. Instead, produce a .rock file
25 with the contents of compilation in the current
26 directory.
27
28--keep Do not remove previously installed versions of the
29 rock after building a new one. This behavior can
30 be made permanent by setting keep_other_versions=true
31 in the configuration file.
32
33--branch=<name> Override the `source.branch` field in the loaded
34 rockspec. Allows to specify a different branch to
35 fetch. Particularly for SCM rocks.
36
37--only-deps Installs only the dependencies of the rock.
38
39]]..util.deps_mode_help()
40
41--- Build and install a rock.
42-- @param rock_file string: local or remote filename of a rock.
43-- @param need_to_fetch boolean: true if sources need to be fetched,
44-- false if the rockspec was obtained from inside a source rock.
45-- @param deps_mode: string: Which trees to check dependencies for:
46-- "one" for the current default tree, "all" for all trees,
47-- "order" for all trees with priority >= the current default, "none" for no trees.
48-- @param build_only_deps boolean: true to build the listed dependencies only.
49-- @return boolean or (nil, string, [string]): True if build was successful,
50-- or false and an error message and an optional error code.
51local function build_rock(rock_file, need_to_fetch, deps_mode, build_only_deps)
52 assert(type(rock_file) == "string")
53 assert(type(need_to_fetch) == "boolean")
54
55 local ok, err, errcode
56 local unpack_dir
57 unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file)
58 if not unpack_dir then
59 return nil, err, errcode
60 end
61 local rockspec_file = path.rockspec_name_from_rock(rock_file)
62 ok, err = fs.change_dir(unpack_dir)
63 if not ok then return nil, err end
64 ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode, build_only_deps)
65 fs.pop_dir()
66 return ok, err, errcode
67end
68
69local function do_build(name, version, deps_mode, build_only_deps)
70 if name:match("%.rockspec$") then
71 return build.build_rockspec(name, true, false, deps_mode, build_only_deps)
72 elseif name:match("%.src%.rock$") then
73 return build_rock(name, false, deps_mode, build_only_deps)
74 elseif name:match("%.all%.rock$") then
75 return build_rock(name, true, deps_mode, build_only_deps)
76 elseif name:match("%.rock$") then
77 return build_rock(name, true, deps_mode, build_only_deps)
78 elseif not name:match(dir.separator) then
79 local search = require("luarocks.search")
80 return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps)
81 end
82 return nil, "Don't know what to do with "..name
83end
84
85--- Driver function for "build" command.
86-- @param name string: A local or remote rockspec or rock file.
87-- If a package name is given, forwards the request to "search" and,
88-- if returned a result, installs the matching rock.
89-- @param version string: When passing a package name, a version number may
90-- also be given.
91-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
92-- error message otherwise. exitcode is optionally returned.
93function cmd_build.command(flags, name, version)
94 if type(name) ~= "string" then
95 return nil, "Argument missing. "..util.see_help("build")
96 end
97 assert(type(version) == "string" or not version)
98
99 if flags["pack-binary-rock"] then
100 return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags))
101 else
102 local ok, err = fs.check_command_permissions(flags)
103 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
104 ok, err = do_build(name, version, deps.get_deps_mode(flags), flags["only-deps"])
105 if not ok then return nil, err end
106 name, version = ok, err
107 if flags["only-deps"] then
108 return name, version
109 end
110 if (not flags["keep"]) and not cfg.keep_other_versions then
111 local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"])
112 if not ok then util.printerr(err) end
113 end
114 return name, version
115 end
116end
117
118return cmd_build
diff --git a/src/luarocks/config_cmd.lua b/src/luarocks/cmd/config_cmd.lua
index b68f7898..b68f7898 100644
--- a/src/luarocks/config_cmd.lua
+++ b/src/luarocks/cmd/config_cmd.lua
diff --git a/src/luarocks/doc.lua b/src/luarocks/cmd/doc.lua
index 5d521276..5d521276 100644
--- a/src/luarocks/doc.lua
+++ b/src/luarocks/cmd/doc.lua
diff --git a/src/luarocks/cmd/download.lua b/src/luarocks/cmd/download.lua
new file mode 100644
index 00000000..9c119f6e
--- /dev/null
+++ b/src/luarocks/cmd/download.lua
@@ -0,0 +1,45 @@
1
2--- Module implementing the luarocks "download" command.
3-- Download a rock from the repository.
4local cmd_download = {}
5
6local util = require("luarocks.util")
7local download = require("luarocks.download")
8
9cmd_download.help_summary = "Download a specific rock file from a rocks server."
10cmd_download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]"
11cmd_download.help = [[
12--all Download all files if there are multiple matches.
13--source Download .src.rock if available.
14--rockspec Download .rockspec if available.
15--arch=<arch> Download rock for a specific architecture.
16]]
17
18--- Driver function for the "download" command.
19-- @param name string: a rock name.
20-- @param version string or nil: if the name of a package is given, a
21-- version may also be passed.
22-- @return boolean or (nil, string): true if successful or nil followed
23-- by an error message.
24function cmd_download.command(flags, name, version)
25 assert(type(version) == "string" or not version)
26 if type(name) ~= "string" and not flags["all"] then
27 return nil, "Argument missing. "..util.see_help("download")
28 end
29 if not name then name, version = "", "" end
30
31 local arch
32
33 if flags["source"] then
34 arch = "src"
35 elseif flags["rockspec"] then
36 arch = "rockspec"
37 elseif flags["arch"] then
38 arch = flags["arch"]
39 end
40
41 local dl, err = download.download(arch, name:lower(), version, flags["all"])
42 return dl and true, err
43end
44
45return cmd_download
diff --git a/src/luarocks/help.lua b/src/luarocks/cmd/help.lua
index d27c3a50..d27c3a50 100644
--- a/src/luarocks/help.lua
+++ b/src/luarocks/cmd/help.lua
diff --git a/src/luarocks/install.lua b/src/luarocks/cmd/install.lua
index c9b085f5..33cc8fbf 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/cmd/install.lua
@@ -10,6 +10,7 @@ local fs = require("luarocks.fs")
10local deps = require("luarocks.deps") 10local deps = require("luarocks.deps")
11local writer = require("luarocks.manif.writer") 11local writer = require("luarocks.manif.writer")
12local remove = require("luarocks.remove") 12local remove = require("luarocks.remove")
13local search = require("luarocks.search")
13local cfg = require("luarocks.core.cfg") 14local cfg = require("luarocks.core.cfg")
14 15
15install.help_summary = "Install a rock." 16install.help_summary = "Install a rock."
@@ -154,7 +155,7 @@ function install.command(flags, name, version)
154 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end 155 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
155 156
156 if name:match("%.rockspec$") or name:match("%.src%.rock$") then 157 if name:match("%.rockspec$") or name:match("%.src%.rock$") then
157 local build = require("luarocks.build") 158 local build = require("luarocks.cmd.build")
158 return build.command(flags, name) 159 return build.command(flags, name)
159 elseif name:match("%.rock$") then 160 elseif name:match("%.rock$") then
160 if flags["only-deps"] then 161 if flags["only-deps"] then
@@ -170,7 +171,6 @@ function install.command(flags, name, version)
170 end 171 end
171 return name, version 172 return name, version
172 else 173 else
173 local search = require("luarocks.search")
174 local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) 174 local url, err = search.find_suitable_rock(search.make_query(name:lower(), version))
175 if not url then 175 if not url then
176 return nil, err 176 return nil, err
diff --git a/src/luarocks/lint.lua b/src/luarocks/cmd/lint.lua
index c9ea45ea..c9ea45ea 100644
--- a/src/luarocks/lint.lua
+++ b/src/luarocks/cmd/lint.lua
diff --git a/src/luarocks/list.lua b/src/luarocks/cmd/list.lua
index 45f1a26f..45f1a26f 100644
--- a/src/luarocks/list.lua
+++ b/src/luarocks/cmd/list.lua
diff --git a/src/luarocks/make.lua b/src/luarocks/cmd/make.lua
index eb38bff0..eb38bff0 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/cmd/make.lua
diff --git a/src/luarocks/new_version.lua b/src/luarocks/cmd/new_version.lua
index b13dbb97..b13dbb97 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/cmd/new_version.lua
diff --git a/src/luarocks/cmd/pack.lua b/src/luarocks/cmd/pack.lua
new file mode 100644
index 00000000..e43e5b3f
--- /dev/null
+++ b/src/luarocks/cmd/pack.lua
@@ -0,0 +1,45 @@
1
2--- Module implementing the LuaRocks "pack" command.
3-- Creates a rock, packing sources or binaries.
4local cmd_pack = {}
5
6local util = require("luarocks.util")
7local pack = require("luarocks.pack")
8
9cmd_pack.help_summary = "Create a rock, packing sources or binaries."
10cmd_pack.help_arguments = "{<rockspec>|<name> [<version>]}"
11cmd_pack.help = [[
12Argument may be a rockspec file, for creating a source rock,
13or the name of an installed package, for creating a binary rock.
14In the latter case, the app version may be given as a second
15argument.
16]]
17
18--- Driver function for the "pack" command.
19-- @param arg string: may be a rockspec file, for creating a source rock,
20-- or the name of an installed package, for creating a binary rock.
21-- @param version string or nil: if the name of a package is given, a
22-- version may also be passed.
23-- @return boolean or (nil, string): true if successful or nil followed
24-- by an error message.
25function cmd_pack.command(flags, arg, version)
26 assert(type(version) == "string" or not version)
27 if type(arg) ~= "string" then
28 return nil, "Argument missing. "..util.see_help("pack")
29 end
30
31 local file, err
32 if arg:match(".*%.rockspec") then
33 file, err = pack.pack_source_rock(arg)
34 else
35 file, err = pack.pack_installed_rock(arg:lower(), version, flags["tree"])
36 end
37 if err then
38 return nil, err
39 else
40 util.printout("Packed: "..file)
41 return true
42 end
43end
44
45return cmd_pack
diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/cmd/path_cmd.lua
index 516a0c47..516a0c47 100644
--- a/src/luarocks/path_cmd.lua
+++ b/src/luarocks/cmd/path_cmd.lua
diff --git a/src/luarocks/purge.lua b/src/luarocks/cmd/purge.lua
index 50f290c8..50f290c8 100644
--- a/src/luarocks/purge.lua
+++ b/src/luarocks/cmd/purge.lua
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua
new file mode 100644
index 00000000..08d49058
--- /dev/null
+++ b/src/luarocks/cmd/remove.lua
@@ -0,0 +1,59 @@
1
2--- Module implementing the LuaRocks "remove" command.
3-- Uninstalls rocks.
4local cmd_remove = {}
5
6local remove = require("luarocks.remove")
7local util = require("luarocks.util")
8local cfg = require("luarocks.core.cfg")
9local fs = require("luarocks.fs")
10local search = require("luarocks.search")
11local path = require("luarocks.path")
12
13cmd_remove.help_summary = "Uninstall a rock."
14cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]"
15cmd_remove.help = [[
16Argument is the name of a rock to be uninstalled.
17If a version is not given, try to remove all versions at once.
18Will only perform the removal if it does not break dependencies.
19To override this check and force the removal, use --force.
20To perform a forced removal without reporting dependency issues,
21use --force-fast.
22
23]]..util.deps_mode_help()
24
25--- Driver function for the "remove" command.
26-- @param name string: name of a rock. If a version is given, refer to
27-- a specific version; otherwise, try to remove all versions.
28-- @param version string: When passing a package name, a version number
29-- may also be given.
30-- @return boolean or (nil, string, exitcode): True if removal was
31-- successful, nil and an error message otherwise. exitcode is optionally returned.
32function cmd_remove.command(flags, name, version)
33 if type(name) ~= "string" then
34 return nil, "Argument missing. "..util.see_help("remove")
35 end
36
37 local deps_mode = flags["deps-mode"] or cfg.deps_mode
38
39 local ok, err = fs.check_command_permissions(flags)
40 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
41
42 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$")
43 local filename = name
44 if rock_type then
45 name, version = path.parse_name(filename)
46 if not name then return nil, "Invalid "..rock_type.." filename: "..filename end
47 end
48
49 local results = {}
50 name = name:lower()
51 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version))
52 if not results[name] then
53 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir)
54 end
55
56 return remove.remove_search_results(results, name, deps_mode, flags["force"], flags["force-fast"])
57end
58
59return cmd_remove
diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua
new file mode 100644
index 00000000..c4e4058d
--- /dev/null
+++ b/src/luarocks/cmd/search.lua
@@ -0,0 +1,74 @@
1
2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers.
4local cmd_search = {}
5
6local cfg = require("luarocks.core.cfg")
7local util = require("luarocks.util")
8local search = require("luarocks.search")
9
10cmd_search.help_summary = "Query the LuaRocks servers."
11cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }"
12cmd_search.help = [[
13--source Return only rockspecs and source rocks,
14 to be used with the "build" command.
15--binary Return only pure Lua and binary rocks (rocks that can be used
16 with the "install" command without requiring a C toolchain).
17--all List all contents of the server that are suitable to
18 this platform, do not filter by name.
19]]
20
21--- Splits a list of search results into two lists, one for "source" results
22-- to be used with the "build" command, and one for "binary" results to be
23-- used with the "install" command.
24-- @param results table: A search results table.
25-- @return (table, table): Two tables, one for source and one for binary
26-- results.
27local function split_source_and_binary_results(results)
28 local sources, binaries = {}, {}
29 for name, versions in pairs(results) do
30 for version, repositories in pairs(versions) do
31 for _, repo in ipairs(repositories) do
32 local where = sources
33 if repo.arch == "all" or repo.arch == cfg.arch then
34 where = binaries
35 end
36 search.store_result(where, name, version, repo.arch, repo.repo)
37 end
38 end
39 end
40 return sources, binaries
41end
42
43--- Driver function for "search" command.
44-- @param name string: A substring of a rock name to search.
45-- @param version string or nil: a version may also be passed.
46-- @return boolean or (nil, string): True if build was successful; nil and an
47-- error message otherwise.
48function cmd_search.command(flags, name, version)
49 if flags["all"] then
50 name, version = "", nil
51 end
52
53 if type(name) ~= "string" and not flags["all"] then
54 return nil, "Enter name and version or use --all. "..util.see_help("search")
55 end
56
57 local query = search.make_query(name:lower(), version)
58 query.exact_name = false
59 local results, err = search.search_repos(query)
60 local porcelain = flags["porcelain"]
61 util.title("Search results:", porcelain, "=")
62 local sources, binaries = split_source_and_binary_results(results)
63 if next(sources) and not flags["binary"] then
64 util.title("Rockspecs and source rocks:", porcelain)
65 search.print_results(sources, porcelain)
66 end
67 if next(binaries) and not flags["source"] then
68 util.title("Binary and pure-Lua rocks:", porcelain)
69 search.print_results(binaries, porcelain)
70 end
71 return true
72end
73
74return cmd_search
diff --git a/src/luarocks/show.lua b/src/luarocks/cmd/show.lua
index 1ff81e08..1ff81e08 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/cmd/show.lua
diff --git a/src/luarocks/unpack.lua b/src/luarocks/cmd/unpack.lua
index c50701b0..c50701b0 100644
--- a/src/luarocks/unpack.lua
+++ b/src/luarocks/cmd/unpack.lua
diff --git a/src/luarocks/upload.lua b/src/luarocks/cmd/upload.lua
index baee47ab..baee47ab 100644
--- a/src/luarocks/upload.lua
+++ b/src/luarocks/cmd/upload.lua
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua
index be563eaa..be563eaa 100644
--- a/src/luarocks/write_rockspec.lua
+++ b/src/luarocks/cmd/write_rockspec.lua
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index acbf1dd6..081265a5 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -240,7 +240,7 @@ end
240function deps.fulfill_dependencies(rockspec, deps_mode) 240function deps.fulfill_dependencies(rockspec, deps_mode)
241 241
242 local search = require("luarocks.search") 242 local search = require("luarocks.search")
243 local install = require("luarocks.install") 243 local install = require("luarocks.cmd.install")
244 244
245 if rockspec.supported_platforms then 245 if rockspec.supported_platforms then
246 if not deps.platforms_set then 246 if not deps.platforms_set then
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index 557d1b65..ec9996b2 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -1,9 +1,5 @@
1
2--- Module implementing the luarocks "download" command.
3-- Download a rock from the repository.
4local download = {} 1local download = {}
5 2
6local util = require("luarocks.util")
7local path = require("luarocks.path") 3local path = require("luarocks.path")
8local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
9local search = require("luarocks.search") 5local search = require("luarocks.search")
@@ -11,16 +7,6 @@ local fs = require("luarocks.fs")
11local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
12local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
13 9
14download.help_summary = "Download a specific rock file from a rocks server."
15download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]"
16
17download.help = [[
18--all Download all files if there are multiple matches.
19--source Download .src.rock if available.
20--rockspec Download .rockspec if available.
21--arch=<arch> Download rock for a specific architecture.
22]]
23
24local function get_file(filename) 10local function get_file(filename)
25 local protocol, pathname = dir.split_url(filename) 11 local protocol, pathname = dir.split_url(filename)
26 if protocol == "file" then 12 if protocol == "file" then
@@ -77,31 +63,4 @@ function download.download(arch, name, version, all)
77 (search_err and ": "..search_err or ".") 63 (search_err and ": "..search_err or ".")
78end 64end
79 65
80--- Driver function for the "download" command.
81-- @param name string: a rock name.
82-- @param version string or nil: if the name of a package is given, a
83-- version may also be passed.
84-- @return boolean or (nil, string): true if successful or nil followed
85-- by an error message.
86function download.command(flags, name, version)
87 assert(type(version) == "string" or not version)
88 if type(name) ~= "string" and not flags["all"] then
89 return nil, "Argument missing. "..util.see_help("download")
90 end
91 if not name then name, version = "", "" end
92
93 local arch
94
95 if flags["source"] then
96 arch = "src"
97 elseif flags["rockspec"] then
98 arch = "rockspec"
99 elseif flags["arch"] then
100 arch = flags["arch"]
101 end
102
103 local dl, err = download.download(arch, name:lower(), version, flags["all"])
104 return dl and true, err
105end
106
107return download 66return download
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index 655cbf37..b721a209 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -1,6 +1,5 @@
1 1
2--- Module implementing the LuaRocks "pack" command. 2-- Create rock files, packing sources or binaries.
3-- Creates a rock, packing sources or binaries.
4local pack = {} 3local pack = {}
5 4
6local unpack = unpack or table.unpack 5local unpack = unpack or table.unpack
@@ -15,15 +14,6 @@ local dir = require("luarocks.dir")
15local manif = require("luarocks.manif") 14local manif = require("luarocks.manif")
16local search = require("luarocks.search") 15local search = require("luarocks.search")
17 16
18pack.help_summary = "Create a rock, packing sources or binaries."
19pack.help_arguments = "{<rockspec>|<name> [<version>]}"
20pack.help = [[
21Argument may be a rockspec file, for creating a source rock,
22or the name of an installed package, for creating a binary rock.
23In the latter case, the app version may be given as a second
24argument.
25]]
26
27--- Create a source rock. 17--- Create a source rock.
28-- Packages a rockspec and its required source files in a rock 18-- Packages a rockspec and its required source files in a rock
29-- file with the .src.rock extension, which can later be built and 19-- file with the .src.rock extension, which can later be built and
@@ -86,7 +76,7 @@ end
86-- @param tree string or nil: An optional tree to pick the package from. 76-- @param tree string or nil: An optional tree to pick the package from.
87-- @return string or (nil, string): The filename of the resulting 77-- @return string or (nil, string): The filename of the resulting
88-- .src.rock file; or nil and an error message. 78-- .src.rock file; or nil and an error message.
89local function do_pack_binary_rock(name, version, tree) 79function pack.pack_installed_rock(name, version, tree)
90 assert(type(name) == "string") 80 assert(type(name) == "string")
91 assert(type(version) == "string" or not version) 81 assert(type(version) == "string" or not version)
92 82
@@ -160,34 +150,7 @@ function pack.pack_binary_rock(name, version, cmd, ...)
160 if not rname then 150 if not rname then
161 rname, rversion = name, version 151 rname, rversion = name, version
162 end 152 end
163 return do_pack_binary_rock(rname, rversion, temp_dir) 153 return pack.pack_installed_rock(rname, rversion, temp_dir)
164end
165
166--- Driver function for the "pack" command.
167-- @param arg string: may be a rockspec file, for creating a source rock,
168-- or the name of an installed package, for creating a binary rock.
169-- @param version string or nil: if the name of a package is given, a
170-- version may also be passed.
171-- @return boolean or (nil, string): true if successful or nil followed
172-- by an error message.
173function pack.command(flags, arg, version)
174 assert(type(version) == "string" or not version)
175 if type(arg) ~= "string" then
176 return nil, "Argument missing. "..util.see_help("pack")
177 end
178
179 local file, err
180 if arg:match(".*%.rockspec") then
181 file, err = pack.pack_source_rock(arg)
182 else
183 file, err = do_pack_binary_rock(arg:lower(), version, flags["tree"])
184 end
185 if err then
186 return nil, err
187 else
188 util.printout("Packed: "..file)
189 return true
190 end
191end 154end
192 155
193return pack 156return pack
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index e7f37604..6cc8334f 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -1,6 +1,3 @@
1
2--- Module implementing the LuaRocks "remove" command.
3-- Uninstalls rocks.
4local remove = {} 1local remove = {}
5 2
6local search = require("luarocks.search") 3local search = require("luarocks.search")
@@ -10,19 +7,6 @@ local repos = require("luarocks.repos")
10local path = require("luarocks.path") 7local path = require("luarocks.path")
11local util = require("luarocks.util") 8local util = require("luarocks.util")
12local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
13local fs = require("luarocks.fs")
14
15remove.help_summary = "Uninstall a rock."
16remove.help_arguments = "[--force|--force-fast] <name> [<version>]"
17remove.help = [[
18Argument is the name of a rock to be uninstalled.
19If a version is not given, try to remove all versions at once.
20Will only perform the removal if it does not break dependencies.
21To override this check and force the removal, use --force.
22To perform a forced removal without reporting dependency issues,
23use --force-fast.
24
25]]..util.deps_mode_help()
26 10
27--- Obtain a list of packages that depend on the given set of packages 11--- Obtain a list of packages that depend on the given set of packages
28-- (where all packages of the set are versions of one program). 12-- (where all packages of the set are versions of one program).
@@ -128,38 +112,4 @@ function remove.remove_other_versions(name, version, force, fast)
128 return true 112 return true
129end 113end
130 114
131--- Driver function for the "remove" command.
132-- @param name string: name of a rock. If a version is given, refer to
133-- a specific version; otherwise, try to remove all versions.
134-- @param version string: When passing a package name, a version number
135-- may also be given.
136-- @return boolean or (nil, string, exitcode): True if removal was
137-- successful, nil and an error message otherwise. exitcode is optionally returned.
138function remove.command(flags, name, version)
139 if type(name) ~= "string" then
140 return nil, "Argument missing. "..util.see_help("remove")
141 end
142
143 local deps_mode = flags["deps-mode"] or cfg.deps_mode
144
145 local ok, err = fs.check_command_permissions(flags)
146 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
147
148 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$")
149 local filename = name
150 if rock_type then
151 name, version = path.parse_name(filename)
152 if not name then return nil, "Invalid "..rock_type.." filename: "..filename end
153 end
154
155 local results = {}
156 name = name:lower()
157 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version))
158 if not results[name] then
159 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir)
160 end
161
162 return remove.remove_search_results(results, name, deps_mode, flags["force"], flags["force-fast"])
163end
164
165return remove 115return remove
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 44eff694..c59f9534 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -1,9 +1,5 @@
1
2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers.
4local search = {} 1local search = {}
5 2
6
7local dir = require("luarocks.dir") 3local dir = require("luarocks.dir")
8local path = require("luarocks.path") 4local path = require("luarocks.path")
9local manif = require("luarocks.manif") 5local manif = require("luarocks.manif")
@@ -11,17 +7,6 @@ local deps = require("luarocks.deps")
11local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
12local util = require("luarocks.util") 8local util = require("luarocks.util")
13 9
14search.help_summary = "Query the LuaRocks servers."
15search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }"
16search.help = [[
17--source Return only rockspecs and source rocks,
18 to be used with the "build" command.
19--binary Return only pure Lua and binary rocks (rocks that can be used
20 with the "install" command without requiring a C toolchain).
21--all List all contents of the server that are suitable to
22 this platform, do not filter by name.
23]]
24
25--- Convert the arch field of a query table to table format. 10--- Convert the arch field of a query table to table format.
26-- @param query table: A query table. 11-- @param query table: A query table.
27local function query_arch_as_table(query) 12local function query_arch_as_table(query)
@@ -55,7 +40,7 @@ end
55-- identifier), "rockspec" or "installed" 40-- identifier), "rockspec" or "installed"
56-- @param repo string: Pathname of a local repository of URL of 41-- @param repo string: Pathname of a local repository of URL of
57-- rocks server. 42-- rocks server.
58local function store_result(results, name, version, arch, repo) 43function search.store_result(results, name, version, arch, repo)
59 assert(type(results) == "table") 44 assert(type(results) == "table")
60 assert(type(name) == "string") 45 assert(type(name) == "string")
61 assert(type(version) == "string") 46 assert(type(version) == "string")
@@ -108,7 +93,7 @@ local function store_if_match(results, repo, name, version, arch, query)
108 if match_name(query, name) then 93 if match_name(query, name) then
109 if query.arch[arch] or query.arch["any"] then 94 if query.arch[arch] or query.arch["any"] then
110 if deps.match_constraints(deps.parse_version(version), query.constraints) then 95 if deps.match_constraints(deps.parse_version(version), query.constraints) then
111 store_result(results, name, version, arch, repo) 96 search.store_result(results, name, version, arch, repo)
112 end 97 end
113 end 98 end
114 end 99 end
@@ -370,28 +355,6 @@ function search.print_results(results, porcelain)
370 end 355 end
371end 356end
372 357
373--- Splits a list of search results into two lists, one for "source" results
374-- to be used with the "build" command, and one for "binary" results to be
375-- used with the "install" command.
376-- @param results table: A search results table.
377-- @return (table, table): Two tables, one for source and one for binary
378-- results.
379local function split_source_and_binary_results(results)
380 local sources, binaries = {}, {}
381 for name, versions in pairs(results) do
382 for version, repositories in pairs(versions) do
383 for _, repo in ipairs(repositories) do
384 local where = sources
385 if repo.arch == "all" or repo.arch == cfg.arch then
386 where = binaries
387 end
388 store_result(where, name, version, repo.arch, repo.repo)
389 end
390 end
391 end
392 return sources, binaries
393end
394
395--- Given a name and optionally a version, try to find in the rocks 358--- Given a name and optionally a version, try to find in the rocks
396-- servers a single .src.rock or .rockspec file that satisfies 359-- servers a single .src.rock or .rockspec file that satisfies
397-- the request, and run the given function on it; or display to the 360-- the request, and run the given function on it; or display to the
@@ -448,35 +411,4 @@ function search.pick_installed_rock(name, version, given_tree)
448 return name, version, repo, repo_url 411 return name, version, repo, repo_url
449end 412end
450 413
451--- Driver function for "search" command.
452-- @param name string: A substring of a rock name to search.
453-- @param version string or nil: a version may also be passed.
454-- @return boolean or (nil, string): True if build was successful; nil and an
455-- error message otherwise.
456function search.command(flags, name, version)
457 if flags["all"] then
458 name, version = "", nil
459 end
460
461 if type(name) ~= "string" and not flags["all"] then
462 return nil, "Enter name and version or use --all. "..util.see_help("search")
463 end
464
465 local query = search.make_query(name:lower(), version)
466 query.exact_name = false
467 local results, err = search.search_repos(query)
468 local porcelain = flags["porcelain"]
469 util.title("Search results:", porcelain, "=")
470 local sources, binaries = split_source_and_binary_results(results)
471 if next(sources) and not flags["binary"] then
472 util.title("Rockspecs and source rocks:", porcelain)
473 search.print_results(sources, porcelain)
474 end
475 if next(binaries) and not flags["source"] then
476 util.title("Binary and pure-Lua rocks:", porcelain)
477 search.print_results(binaries, porcelain)
478 end
479 return true
480end
481
482return search 414return search