diff options
author | Hisham <hisham@gobolinux.org> | 2016-10-30 23:42:46 -0200 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-10-30 23:42:46 -0200 |
commit | 7090601b6b7288f0194b58f9d0e168392c8e6690 (patch) | |
tree | 67622cf4bfa7e0e27cfe52e3e3c5d302056424d4 /src | |
parent | a7c10e670c2f682962e28984a43916f40b302b2b (diff) | |
parent | 27be765c4a846c0d4e970e154b29cbab1a833738 (diff) | |
download | luarocks-7090601b6b7288f0194b58f9d0e168392c8e6690.tar.gz luarocks-7090601b6b7288f0194b58f9d0e168392c8e6690.tar.bz2 luarocks-7090601b6b7288f0194b58f9d0e168392c8e6690.zip |
Merge branch 'new-cmd-dir' into luarocks-3
Diffstat (limited to 'src')
-rwxr-xr-x | src/bin/luarocks | 38 | ||||
-rwxr-xr-x | src/bin/luarocks-admin | 10 | ||||
-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.lua | 111 | ||||
-rw-r--r-- | src/luarocks/cmd/build.lua | 119 | ||||
-rw-r--r-- | src/luarocks/cmd/config.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.lua | 45 | ||||
-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.lua | 45 | ||||
-rw-r--r-- | src/luarocks/cmd/path.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.lua | 67 | ||||
-rw-r--r-- | src/luarocks/cmd/search.lua | 74 | ||||
-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.lua | 2 | ||||
-rw-r--r-- | src/luarocks/download.lua | 41 | ||||
-rw-r--r-- | src/luarocks/manif/writer.lua | 4 | ||||
-rw-r--r-- | src/luarocks/pack.lua | 43 | ||||
-rw-r--r-- | src/luarocks/remove.lua | 57 | ||||
-rw-r--r-- | src/luarocks/search.lua | 72 |
32 files changed, 387 insertions, 345 deletions
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") | |||
9 | program_description = "LuaRocks main command-line interface" | 9 | program_description = "LuaRocks main command-line interface" |
10 | 10 | ||
11 | commands = { | 11 | commands = { |
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 | ||
33 | command_line.run_command(...) | 33 | command_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") | |||
9 | program_description = "LuaRocks repository administration interface" | 9 | program_description = "LuaRocks repository administration interface" |
10 | 10 | ||
11 | commands = { | 11 | commands = { |
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 | ||
19 | command_line.run_command(...) | 19 | command_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 7808bce9..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. | ||
4 | local build = {} | 2 | local build = {} |
5 | 3 | ||
6 | local pack = require("luarocks.pack") | ||
7 | local path = require("luarocks.path") | 4 | local path = require("luarocks.path") |
8 | local util = require("luarocks.util") | 5 | local util = require("luarocks.util") |
9 | local repos = require("luarocks.repos") | ||
10 | local fetch = require("luarocks.fetch") | 6 | local fetch = require("luarocks.fetch") |
11 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
12 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
13 | local deps = require("luarocks.deps") | 9 | local deps = require("luarocks.deps") |
14 | local writer = require("luarocks.manif.writer") | ||
15 | local remove = require("luarocks.remove") | ||
16 | local cfg = require("luarocks.core.cfg") | 10 | local cfg = require("luarocks.core.cfg") |
17 | 11 | local repos = require("luarocks.repos") | |
18 | build.help_summary = "Build/compile a rock." | 12 | local writer = require("luarocks.manif.writer") |
19 | build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" | ||
20 | build.help = [[ | ||
21 | Build and install a rock, compiling its C parts if any. | ||
22 | Argument may be a rockspec file, a source rock file | ||
23 | or 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 |
362 | end | 334 | end |
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. | ||
374 | function 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 | ||
390 | end | ||
391 | |||
392 | local 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 | ||
408 | end | ||
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. | ||
418 | function 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 | |||
433 | if (not flags["only-deps"]) and (not flags["keep"]) and not cfg.keep_other_versions then | ||
434 | local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"]) | ||
435 | if not ok then util.printerr(err) end | ||
436 | end | ||
437 | |||
438 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) | ||
439 | return name, version | ||
440 | end | ||
441 | end | ||
442 | |||
443 | return build | 336 | return build |
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua new file mode 100644 index 00000000..a6b67b92 --- /dev/null +++ b/src/luarocks/cmd/build.lua | |||
@@ -0,0 +1,119 @@ | |||
1 | |||
2 | --- Module implementing the LuaRocks "build" command. | ||
3 | -- Builds a rock, compiling its C parts if any. | ||
4 | local cmd_build = {} | ||
5 | |||
6 | local pack = require("luarocks.pack") | ||
7 | local path = require("luarocks.path") | ||
8 | local util = require("luarocks.util") | ||
9 | local fetch = require("luarocks.fetch") | ||
10 | local fs = require("luarocks.fs") | ||
11 | local dir = require("luarocks.dir") | ||
12 | local deps = require("luarocks.deps") | ||
13 | local remove = require("luarocks.remove") | ||
14 | local cfg = require("luarocks.core.cfg") | ||
15 | local build = require("luarocks.build") | ||
16 | local writer = require("luarocks.manif.writer") | ||
17 | |||
18 | cmd_build.help_summary = "build/compile a rock." | ||
19 | cmd_build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" | ||
20 | cmd_build.help = [[ | ||
21 | Build and install a rock, compiling its C parts if any. | ||
22 | Argument may be a rockspec file, a source rock file | ||
23 | or 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 | |||
42 | --- Build and install a rock. | ||
43 | -- @param rock_file string: local or remote filename of a rock. | ||
44 | -- @param need_to_fetch boolean: true if sources need to be fetched, | ||
45 | -- false if the rockspec was obtained from inside a source rock. | ||
46 | -- @param deps_mode: string: Which trees to check dependencies for: | ||
47 | -- "one" for the current default tree, "all" for all trees, | ||
48 | -- "order" for all trees with priority >= the current default, "none" for no trees. | ||
49 | -- @param build_only_deps boolean: true to build the listed dependencies only. | ||
50 | -- @return boolean or (nil, string, [string]): True if build was successful, | ||
51 | -- or false and an error message and an optional error code. | ||
52 | local function build_rock(rock_file, need_to_fetch, deps_mode, build_only_deps) | ||
53 | assert(type(rock_file) == "string") | ||
54 | assert(type(need_to_fetch) == "boolean") | ||
55 | |||
56 | local ok, err, errcode | ||
57 | local unpack_dir | ||
58 | unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file) | ||
59 | if not unpack_dir then | ||
60 | return nil, err, errcode | ||
61 | end | ||
62 | local rockspec_file = path.rockspec_name_from_rock(rock_file) | ||
63 | ok, err = fs.change_dir(unpack_dir) | ||
64 | if not ok then return nil, err end | ||
65 | ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode, build_only_deps) | ||
66 | fs.pop_dir() | ||
67 | return ok, err, errcode | ||
68 | end | ||
69 | |||
70 | local function do_build(name, version, deps_mode, build_only_deps) | ||
71 | if name:match("%.rockspec$") then | ||
72 | return build.build_rockspec(name, true, false, deps_mode, build_only_deps) | ||
73 | elseif name:match("%.src%.rock$") then | ||
74 | return build_rock(name, false, deps_mode, build_only_deps) | ||
75 | elseif name:match("%.all%.rock$") then | ||
76 | return build_rock(name, true, deps_mode, build_only_deps) | ||
77 | elseif name:match("%.rock$") then | ||
78 | return build_rock(name, true, deps_mode, build_only_deps) | ||
79 | elseif not name:match(dir.separator) then | ||
80 | local search = require("luarocks.search") | ||
81 | return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps) | ||
82 | end | ||
83 | return nil, "Don't know what to do with "..name | ||
84 | end | ||
85 | |||
86 | --- Driver function for "build" command. | ||
87 | -- @param name string: A local or remote rockspec or rock file. | ||
88 | -- If a package name is given, forwards the request to "search" and, | ||
89 | -- if returned a result, installs the matching rock. | ||
90 | -- @param version string: When passing a package name, a version number may | ||
91 | -- also be given. | ||
92 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | ||
93 | -- error message otherwise. exitcode is optionally returned. | ||
94 | function cmd_build.command(flags, name, version) | ||
95 | if type(name) ~= "string" then | ||
96 | return nil, "Argument missing. "..util.see_help("build") | ||
97 | end | ||
98 | assert(type(version) == "string" or not version) | ||
99 | |||
100 | if flags["pack-binary-rock"] then | ||
101 | return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags)) | ||
102 | else | ||
103 | local ok, err = fs.check_command_permissions(flags) | ||
104 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | ||
105 | ok, err = do_build(name, version, deps.get_deps_mode(flags), flags["only-deps"]) | ||
106 | if not ok then return nil, err end | ||
107 | name, version = ok, err | ||
108 | |||
109 | if (not flags["only-deps"]) and (not flags["keep"]) and not cfg.keep_other_versions then | ||
110 | local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"]) | ||
111 | if not ok then util.printerr(err) end | ||
112 | end | ||
113 | |||
114 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) | ||
115 | return name, version | ||
116 | end | ||
117 | end | ||
118 | |||
119 | return cmd_build | ||
diff --git a/src/luarocks/config_cmd.lua b/src/luarocks/cmd/config.lua index b68f7898..b68f7898 100644 --- a/src/luarocks/config_cmd.lua +++ b/src/luarocks/cmd/config.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. | ||
4 | local cmd_download = {} | ||
5 | |||
6 | local util = require("luarocks.util") | ||
7 | local download = require("luarocks.download") | ||
8 | |||
9 | cmd_download.help_summary = "Download a specific rock file from a rocks server." | ||
10 | cmd_download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" | ||
11 | cmd_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. | ||
24 | function 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 | ||
43 | end | ||
44 | |||
45 | return 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 3a33fcae..8b4a154b 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/cmd/install.lua | |||
@@ -10,6 +10,7 @@ local fs = require("luarocks.fs") | |||
10 | local deps = require("luarocks.deps") | 10 | local deps = require("luarocks.deps") |
11 | local writer = require("luarocks.manif.writer") | 11 | local writer = require("luarocks.manif.writer") |
12 | local remove = require("luarocks.remove") | 12 | local remove = require("luarocks.remove") |
13 | local search = require("luarocks.search") | ||
13 | local cfg = require("luarocks.core.cfg") | 14 | local cfg = require("luarocks.core.cfg") |
14 | 15 | ||
15 | install.help_summary = "Install a rock." | 16 | install.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 |
@@ -173,7 +174,6 @@ function install.command(flags, name, version) | |||
173 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) | 174 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) |
174 | return name, version | 175 | return name, version |
175 | else | 176 | else |
176 | local search = require("luarocks.search") | ||
177 | local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) | 177 | local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) |
178 | if not url then | 178 | if not url then |
179 | return nil, err | 179 | 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 d3d02814..d3d02814 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. | ||
4 | local cmd_pack = {} | ||
5 | |||
6 | local util = require("luarocks.util") | ||
7 | local pack = require("luarocks.pack") | ||
8 | |||
9 | cmd_pack.help_summary = "Create a rock, packing sources or binaries." | ||
10 | cmd_pack.help_arguments = "{<rockspec>|<name> [<version>]}" | ||
11 | cmd_pack.help = [[ | ||
12 | Argument may be a rockspec file, for creating a source rock, | ||
13 | or the name of an installed package, for creating a binary rock. | ||
14 | In the latter case, the app version may be given as a second | ||
15 | argument. | ||
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. | ||
25 | function 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 | ||
43 | end | ||
44 | |||
45 | return cmd_pack | ||
diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/cmd/path.lua index 516a0c47..516a0c47 100644 --- a/src/luarocks/path_cmd.lua +++ b/src/luarocks/cmd/path.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..b8148ba7 --- /dev/null +++ b/src/luarocks/cmd/remove.lua | |||
@@ -0,0 +1,67 @@ | |||
1 | |||
2 | --- Module implementing the LuaRocks "remove" command. | ||
3 | -- Uninstalls rocks. | ||
4 | local cmd_remove = {} | ||
5 | |||
6 | local remove = require("luarocks.remove") | ||
7 | local util = require("luarocks.util") | ||
8 | local cfg = require("luarocks.core.cfg") | ||
9 | local fs = require("luarocks.fs") | ||
10 | local search = require("luarocks.search") | ||
11 | local path = require("luarocks.path") | ||
12 | local deps = require("luarocks.deps") | ||
13 | local writer = require("luarocks.manif.writer") | ||
14 | |||
15 | cmd_remove.help_summary = "Uninstall a rock." | ||
16 | cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" | ||
17 | cmd_remove.help = [[ | ||
18 | Argument is the name of a rock to be uninstalled. | ||
19 | If a version is not given, try to remove all versions at once. | ||
20 | Will only perform the removal if it does not break dependencies. | ||
21 | To override this check and force the removal, use --force. | ||
22 | To perform a forced removal without reporting dependency issues, | ||
23 | use --force-fast. | ||
24 | |||
25 | ]]..util.deps_mode_help() | ||
26 | |||
27 | --- Driver function for the "remove" command. | ||
28 | -- @param name string: name of a rock. If a version is given, refer to | ||
29 | -- a specific version; otherwise, try to remove all versions. | ||
30 | -- @param version string: When passing a package name, a version number | ||
31 | -- may also be given. | ||
32 | -- @return boolean or (nil, string, exitcode): True if removal was | ||
33 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | ||
34 | function cmd_remove.command(flags, name, version) | ||
35 | if type(name) ~= "string" then | ||
36 | return nil, "Argument missing. "..util.see_help("remove") | ||
37 | end | ||
38 | |||
39 | local deps_mode = flags["deps-mode"] or cfg.deps_mode | ||
40 | |||
41 | local ok, err = fs.check_command_permissions(flags) | ||
42 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | ||
43 | |||
44 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") | ||
45 | local filename = name | ||
46 | if rock_type then | ||
47 | name, version = path.parse_name(filename) | ||
48 | if not name then return nil, "Invalid "..rock_type.." filename: "..filename end | ||
49 | end | ||
50 | |||
51 | local results = {} | ||
52 | name = name:lower() | ||
53 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) | ||
54 | if not results[name] then | ||
55 | return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) | ||
56 | end | ||
57 | |||
58 | local ok, err = remove.remove_search_results(results, name, deps_mode, flags["force"], flags["force-fast"]) | ||
59 | if not ok then | ||
60 | return nil, err | ||
61 | end | ||
62 | |||
63 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) | ||
64 | return true | ||
65 | end | ||
66 | |||
67 | return 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. | ||
4 | local cmd_search = {} | ||
5 | |||
6 | local cfg = require("luarocks.core.cfg") | ||
7 | local util = require("luarocks.util") | ||
8 | local search = require("luarocks.search") | ||
9 | |||
10 | cmd_search.help_summary = "Query the LuaRocks servers." | ||
11 | cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" | ||
12 | cmd_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. | ||
27 | local 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 | ||
41 | end | ||
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. | ||
48 | function 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 | ||
72 | end | ||
73 | |||
74 | return 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 d9419ec3..9c737d66 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -262,7 +262,7 @@ end | |||
262 | function deps.fulfill_dependencies(rockspec, deps_mode) | 262 | function deps.fulfill_dependencies(rockspec, deps_mode) |
263 | 263 | ||
264 | local search = require("luarocks.search") | 264 | local search = require("luarocks.search") |
265 | local install = require("luarocks.install") | 265 | local install = require("luarocks.cmd.install") |
266 | 266 | ||
267 | if rockspec.supported_platforms then | 267 | if rockspec.supported_platforms then |
268 | if not deps.platforms_set then | 268 | 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. | ||
4 | local download = {} | 1 | local download = {} |
5 | 2 | ||
6 | local util = require("luarocks.util") | ||
7 | local path = require("luarocks.path") | 3 | local path = require("luarocks.path") |
8 | local fetch = require("luarocks.fetch") | 4 | local fetch = require("luarocks.fetch") |
9 | local search = require("luarocks.search") | 5 | local search = require("luarocks.search") |
@@ -11,16 +7,6 @@ local fs = require("luarocks.fs") | |||
11 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
12 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
13 | 9 | ||
14 | download.help_summary = "Download a specific rock file from a rocks server." | ||
15 | download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" | ||
16 | |||
17 | download.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 | |||
24 | local function get_file(filename) | 10 | local 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 ".") |
78 | end | 64 | end |
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. | ||
86 | function 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 | ||
105 | end | ||
106 | |||
107 | return download | 66 | return download |
diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index cf35f38d..42b92e17 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua | |||
@@ -85,7 +85,7 @@ local function update_dependencies(manifest, deps_mode) | |||
85 | for _, repo in ipairs(repositories) do | 85 | for _, repo in ipairs(repositories) do |
86 | if repo.arch == "installed" then | 86 | if repo.arch == "installed" then |
87 | repo.dependencies = {} | 87 | repo.dependencies = {} |
88 | deps.scan_deps(repo.dependencies, {}, manifest, pkg, version, deps_mode) | 88 | deps.scan_deps(repo.dependencies, manifest, pkg, version, deps_mode) |
89 | repo.dependencies[pkg] = nil | 89 | repo.dependencies[pkg] = nil |
90 | end | 90 | end |
91 | end | 91 | end |
@@ -93,6 +93,8 @@ local function update_dependencies(manifest, deps_mode) | |||
93 | end | 93 | end |
94 | end | 94 | end |
95 | 95 | ||
96 | |||
97 | |||
96 | --- Sort function for ordering rock identifiers in a manifest's | 98 | --- Sort function for ordering rock identifiers in a manifest's |
97 | -- modules table. Rocks are ordered alphabetically by name, and then | 99 | -- modules table. Rocks are ordered alphabetically by name, and then |
98 | -- by version which greater first. | 100 | -- by version which greater first. |
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. | ||
4 | local pack = {} | 3 | local pack = {} |
5 | 4 | ||
6 | local unpack = unpack or table.unpack | 5 | local unpack = unpack or table.unpack |
@@ -15,15 +14,6 @@ local dir = require("luarocks.dir") | |||
15 | local manif = require("luarocks.manif") | 14 | local manif = require("luarocks.manif") |
16 | local search = require("luarocks.search") | 15 | local search = require("luarocks.search") |
17 | 16 | ||
18 | pack.help_summary = "Create a rock, packing sources or binaries." | ||
19 | pack.help_arguments = "{<rockspec>|<name> [<version>]}" | ||
20 | pack.help = [[ | ||
21 | Argument may be a rockspec file, for creating a source rock, | ||
22 | or the name of an installed package, for creating a binary rock. | ||
23 | In the latter case, the app version may be given as a second | ||
24 | argument. | ||
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. |
89 | local function do_pack_binary_rock(name, version, tree) | 79 | function 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) |
164 | end | ||
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. | ||
173 | function 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 | ||
191 | end | 154 | end |
192 | 155 | ||
193 | return pack | 156 | return pack |
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 08b5bd5e..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. | ||
4 | local remove = {} | 1 | local remove = {} |
5 | 2 | ||
6 | local search = require("luarocks.search") | 3 | local search = require("luarocks.search") |
@@ -10,20 +7,6 @@ local repos = require("luarocks.repos") | |||
10 | local path = require("luarocks.path") | 7 | local path = require("luarocks.path") |
11 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
12 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
13 | local fs = require("luarocks.fs") | ||
14 | local writer = require("luarocks.manif.writer") | ||
15 | |||
16 | remove.help_summary = "Uninstall a rock." | ||
17 | remove.help_arguments = "[--force|--force-fast] <name> [<version>]" | ||
18 | remove.help = [[ | ||
19 | Argument is the name of a rock to be uninstalled. | ||
20 | If a version is not given, try to remove all versions at once. | ||
21 | Will only perform the removal if it does not break dependencies. | ||
22 | To override this check and force the removal, use --force. | ||
23 | To perform a forced removal without reporting dependency issues, | ||
24 | use --force-fast. | ||
25 | |||
26 | ]]..util.deps_mode_help() | ||
27 | 10 | ||
28 | --- 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 |
29 | -- (where all packages of the set are versions of one program). | 12 | -- (where all packages of the set are versions of one program). |
@@ -129,44 +112,4 @@ function remove.remove_other_versions(name, version, force, fast) | |||
129 | return true | 112 | return true |
130 | end | 113 | end |
131 | 114 | ||
132 | --- Driver function for the "remove" command. | ||
133 | -- @param name string: name of a rock. If a version is given, refer to | ||
134 | -- a specific version; otherwise, try to remove all versions. | ||
135 | -- @param version string: When passing a package name, a version number | ||
136 | -- may also be given. | ||
137 | -- @return boolean or (nil, string, exitcode): True if removal was | ||
138 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | ||
139 | function remove.command(flags, name, version) | ||
140 | if type(name) ~= "string" then | ||
141 | return nil, "Argument missing. "..util.see_help("remove") | ||
142 | end | ||
143 | |||
144 | local deps_mode = flags["deps-mode"] or cfg.deps_mode | ||
145 | |||
146 | local ok, err = fs.check_command_permissions(flags) | ||
147 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | ||
148 | |||
149 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") | ||
150 | local filename = name | ||
151 | if rock_type then | ||
152 | name, version = path.parse_name(filename) | ||
153 | if not name then return nil, "Invalid "..rock_type.." filename: "..filename end | ||
154 | end | ||
155 | |||
156 | local results = {} | ||
157 | name = name:lower() | ||
158 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) | ||
159 | if not results[name] then | ||
160 | return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) | ||
161 | end | ||
162 | |||
163 | local ok, err = remove.remove_search_results(results, name, deps_mode, flags["force"], flags["force-fast"]) | ||
164 | if not ok then | ||
165 | return nil, err | ||
166 | end | ||
167 | |||
168 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) | ||
169 | return true | ||
170 | end | ||
171 | |||
172 | return remove | 115 | return 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. | ||
4 | local search = {} | 1 | local search = {} |
5 | 2 | ||
6 | |||
7 | local dir = require("luarocks.dir") | 3 | local dir = require("luarocks.dir") |
8 | local path = require("luarocks.path") | 4 | local path = require("luarocks.path") |
9 | local manif = require("luarocks.manif") | 5 | local manif = require("luarocks.manif") |
@@ -11,17 +7,6 @@ local deps = require("luarocks.deps") | |||
11 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
12 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
13 | 9 | ||
14 | search.help_summary = "Query the LuaRocks servers." | ||
15 | search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" | ||
16 | search.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. |
27 | local function query_arch_as_table(query) | 12 | local 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. |
58 | local function store_result(results, name, version, arch, repo) | 43 | function 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 |
371 | end | 356 | end |
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. | ||
379 | local 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 | ||
393 | end | ||
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 |
449 | end | 412 | end |
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. | ||
456 | function 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 | ||
480 | end | ||
481 | |||
482 | return search | 414 | return search |