aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2019-03-20 12:16:48 -0400
committerHisham Muhammad <hisham@gobolinux.org>2019-04-01 17:32:53 -0400
commitb46978faaebeb5954d57b13ff786fea789ab775c (patch)
treef32cce4bae3d52dd73534344ee935c7d6731e80d
parent18842a049784cdbba66010fb30f06525e9016600 (diff)
downloadluarocks-b46978faaebeb5954d57b13ff786fea789ab775c.tar.gz
luarocks-b46978faaebeb5954d57b13ff786fea789ab775c.tar.bz2
luarocks-b46978faaebeb5954d57b13ff786fea789ab775c.zip
Refactor opts_table from build to reuse in install
-rw-r--r--src/luarocks/build.lua42
-rw-r--r--src/luarocks/util.lua29
2 files changed, 37 insertions, 34 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 2e9464cf..130ccd3a 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -12,40 +12,14 @@ local cfg = require("luarocks.core.cfg")
12local repos = require("luarocks.repos") 12local repos = require("luarocks.repos")
13local writer = require("luarocks.manif.writer") 13local writer = require("luarocks.manif.writer")
14 14
15local opts_mt = {} 15build.opts = util.opts_table("build.opts", {
16 16 need_to_fetch = "boolean",
17opts_mt.__index = opts_mt 17 minimal_mode = "boolean",
18 18 deps_mode = "string",
19function opts_mt.type() 19 build_only_deps = "boolean",
20 return "build.opts" 20 namespace = "string?",
21end 21 branch = "boolean",
22 22})
23function build.opts(opts)
24 local valid_opts = {
25 need_to_fetch = "boolean",
26 minimal_mode = "boolean",
27 deps_mode = "string",
28 build_only_deps = "boolean",
29 namespace = "string?",
30 branch = "boolean",
31 }
32 for k, v in pairs(opts) do
33 local tv = type(v)
34 if not valid_opts[k] then
35 error("invalid build option: "..k)
36 end
37 local vo, optional = valid_opts[k]:match("^(.-)(%??)$")
38 if not (tv == vo or (optional == "?" and tv == nil)) then
39 error("invalid type build option: "..k.." - got "..tv..", expected "..vo)
40 end
41 end
42 for k, v in pairs(valid_opts) do
43 if (not v:find("?", 1, true)) and opts[k] == nil then
44 error("missing build option: "..k)
45 end
46 end
47 return setmetatable(opts, opts_mt)
48end
49 23
50do 24do
51 --- Write to the current directory the contents of a table, 25 --- Write to the current directory the contents of a table,
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index bba39457..e370e688 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -657,5 +657,34 @@ do
657 end 657 end
658end 658end
659 659
660function util.opts_table(type_name, valid_opts)
661 local opts_mt = {}
662
663 opts_mt.__index = opts_mt
664
665 function opts_mt.type()
666 return type_name
667 end
668
669 return function(opts)
670 for k, v in pairs(opts) do
671 local tv = type(v)
672 if not valid_opts[k] then
673 error("invalid option: "..k)
674 end
675 local vo, optional = valid_opts[k]:match("^(.-)(%??)$")
676 if not (tv == vo or (optional == "?" and tv == nil)) then
677 error("invalid type option: "..k.." - got "..tv..", expected "..vo)
678 end
679 end
680 for k, v in pairs(valid_opts) do
681 if (not v:find("?", 1, true)) and opts[k] == nil then
682 error("missing option: "..k)
683 end
684 end
685 return setmetatable(opts, opts_mt)
686 end
687end
688
660return util 689return util
661 690