diff options
author | Hisham <hisham@gobolinux.org> | 2016-10-28 20:48:00 -0200 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-10-28 20:48:00 -0200 |
commit | 5bd20308b881c63dd886b71395dbc9baaab25dfd (patch) | |
tree | 8171bda0fed8b391b6195525e2a9c513a5b5c210 | |
parent | 91b7c126a9dcbd9e8f2b37cf07f8e064db2bebb3 (diff) | |
download | luarocks-5bd20308b881c63dd886b71395dbc9baaab25dfd.tar.gz luarocks-5bd20308b881c63dd886b71395dbc9baaab25dfd.tar.bz2 luarocks-5bd20308b881c63dd886b71395dbc9baaab25dfd.zip |
Keep only functions shared among commands
-rw-r--r-- | src/luarocks/build.lua | 111 | ||||
-rw-r--r-- | src/luarocks/download.lua | 45 | ||||
-rw-r--r-- | src/luarocks/pack.lua | 43 | ||||
-rw-r--r-- | src/luarocks/remove.lua | 50 | ||||
-rw-r--r-- | src/luarocks/search.lua | 72 |
5 files changed, 9 insertions, 312 deletions
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. | ||
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 | 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 | ||
441 | end | ||
442 | |||
443 | return build | 336 | return build |
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 557d1b65..c0f2678f 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 |
@@ -46,8 +32,8 @@ function download.download(arch, name, version, all) | |||
46 | local has_result = false | 32 | local has_result = false |
47 | local all_ok = true | 33 | local all_ok = true |
48 | local any_err = "" | 34 | local any_err = "" |
49 | for name, result in pairs(results) do | 35 | for _, result in pairs(results) do |
50 | for version, items in pairs(result) do | 36 | for _, items in pairs(result) do |
51 | for _, item in ipairs(items) do | 37 | for _, item in ipairs(items) do |
52 | -- Ignore provided rocks. | 38 | -- Ignore provided rocks. |
53 | if item.arch ~= "installed" then | 39 | if item.arch ~= "installed" 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/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 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. | ||
4 | local remove = {} | 1 | local remove = {} |
5 | 2 | ||
6 | local search = require("luarocks.search") | 3 | local search = require("luarocks.search") |
@@ -10,19 +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 | |||
15 | remove.help_summary = "Uninstall a rock." | ||
16 | remove.help_arguments = "[--force|--force-fast] <name> [<version>]" | ||
17 | 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 | 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 |
129 | end | 113 | end |
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. | ||
138 | function 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"]) | ||
163 | end | ||
164 | |||
165 | 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 |