aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-29 19:46:34 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:51:22 +0300
commit79096e46d653cfbf06970c2a638855c40232adee (patch)
tree3daf13ba3b51980797fab6b85e29149a68a366ce
parent7d8161f6699e674c760feca300447fc56fd79c32 (diff)
downloadluarocks-79096e46d653cfbf06970c2a638855c40232adee.tar.gz
luarocks-79096e46d653cfbf06970c2a638855c40232adee.tar.bz2
luarocks-79096e46d653cfbf06970c2a638855c40232adee.zip
removing util.opts_table
-rw-r--r--src/luarocks/build.lua16
-rw-r--r--src/luarocks/cmd/install.lua17
-rw-r--r--src/luarocks/persist.tl19
-rw-r--r--src/luarocks/results.tl1
-rw-r--r--src/luarocks/util.lua32
5 files changed, 12 insertions, 73 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index c294b98e..ddaef760 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -14,20 +14,6 @@ local repos = require("luarocks.repos")
14local writer = require("luarocks.manif.writer") 14local writer = require("luarocks.manif.writer")
15local deplocks = require("luarocks.deplocks") 15local deplocks = require("luarocks.deplocks")
16 16
17build.opts = util.opts_table("build.opts", { --WORK
18 need_to_fetch = "boolean",
19 minimal_mode = "boolean",
20 deps_mode = "string",
21 build_only_deps = "boolean",
22 namespace = "string?",
23 branch = "string?",
24 verify = "boolean",
25 check_lua_versions = "boolean",
26 pin = "boolean",
27 rebuild = "boolean",
28 no_install = "boolean"
29})
30
31do 17do
32 --- Write to the current directory the contents of a table, 18 --- Write to the current directory the contents of a table,
33 -- where each key is a file name and its value is the file content. 19 -- where each key is a file name and its value is the file content.
@@ -390,8 +376,6 @@ end
390-- installed rock if succeeded or nil and an error message followed by an error code. 376-- installed rock if succeeded or nil and an error message followed by an error code.
391function build.build_rockspec(rockspec, opts, cwd) 377function build.build_rockspec(rockspec, opts, cwd)
392 assert(rockspec:type() == "rockspec") 378 assert(rockspec:type() == "rockspec")
393 assert(opts:type() == "build.opts")
394 assert(type(cwd) == "string" or type(cwd) == nil)
395 379
396 cwd = cwd or dir.path(".") 380 cwd = cwd or dir.path(".")
397 381
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua
index b50271f0..7102d857 100644
--- a/src/luarocks/cmd/install.lua
+++ b/src/luarocks/cmd/install.lua
@@ -54,15 +54,6 @@ function install.add_to_parser(parser)
54 parser:flag("--sign"):hidden(true) 54 parser:flag("--sign"):hidden(true)
55end 55end
56 56
57install.opts = util.opts_table("install.opts", { --WORK util.opts_table doesn't exist. Make a record
58 namespace = "string?",
59 keep = "boolean",
60 force = "boolean",
61 force_fast = "boolean",
62 no_doc = "boolean",
63 deps_mode = "string",
64 verify = "boolean",
65})
66 57
67--- Install a binary rock. 58--- Install a binary rock.
68-- @param rock_file string: local or remote filename of a rock. 59-- @param rock_file string: local or remote filename of a rock.
@@ -71,7 +62,6 @@ install.opts = util.opts_table("install.opts", { --WORK util.opts_table doesn't
71-- installed rock if succeeded or nil and an error message followed by an error code. 62-- installed rock if succeeded or nil and an error message followed by an error code.
72function install.install_binary_rock(rock_file, opts) 63function install.install_binary_rock(rock_file, opts)
73 assert(type(rock_file) == "string") 64 assert(type(rock_file) == "string")
74 assert(opts:type() == "install.opts")
75 65
76 local namespace = opts.namespace 66 local namespace = opts.namespace
77 local deps_mode = opts.deps_mode 67 local deps_mode = opts.deps_mode
@@ -156,7 +146,6 @@ end
156-- followed by an error code. 146-- followed by an error code.
157function install.install_binary_rock_deps(rock_file, opts) 147function install.install_binary_rock_deps(rock_file, opts)
158 assert(type(rock_file) == "string") 148 assert(type(rock_file) == "string")
159 assert(opts:type() == "install.opts")
160 149
161 local name, version, arch = path.parse_name(rock_file) 150 local name, version, arch = path.parse_name(rock_file)
162 if not name then 151 if not name then
@@ -190,7 +179,6 @@ function install.install_binary_rock_deps(rock_file, opts)
190end 179end
191 180
192local function install_rock_file_deps(filename, opts) 181local function install_rock_file_deps(filename, opts)
193 assert(opts:type() == "install.opts")
194 182
195 local name, version = install.install_binary_rock_deps(filename, opts) 183 local name, version = install.install_binary_rock_deps(filename, opts)
196 if not name then return nil, version end 184 if not name then return nil, version end
@@ -201,7 +189,6 @@ end
201 189
202local function install_rock_file(filename, opts) 190local function install_rock_file(filename, opts)
203 assert(type(filename) == "string") 191 assert(type(filename) == "string")
204 assert(opts:type() == "install.opts")
205 192
206 local name, version = install.install_binary_rock(filename, opts) 193 local name, version = install.install_binary_rock(filename, opts)
207 if not name then return nil, version end 194 if not name then return nil, version end
@@ -237,7 +224,7 @@ function install.command(args)
237 return build.command(args) 224 return build.command(args)
238 elseif args.rock:match("%.rock$") then 225 elseif args.rock:match("%.rock$") then
239 local deps_mode = deps.get_deps_mode(args) 226 local deps_mode = deps.get_deps_mode(args)
240 local opts = install.opts({ 227 local opts = {
241 namespace = args.namespace, 228 namespace = args.namespace,
242 keep = not not args.keep, 229 keep = not not args.keep,
243 force = not not args.force, 230 force = not not args.force,
@@ -245,7 +232,7 @@ function install.command(args)
245 no_doc = not not args.no_doc, 232 no_doc = not not args.no_doc,
246 deps_mode = deps_mode, 233 deps_mode = deps_mode,
247 verify = not not args.verify, 234 verify = not not args.verify,
248 }) 235 }
249 if args.only_deps then 236 if args.only_deps then
250 return install_rock_file_deps(args.rock, opts) 237 return install_rock_file_deps(args.rock, opts)
251 else 238 else
diff --git a/src/luarocks/persist.tl b/src/luarocks/persist.tl
index 46a1bbad..6bd4f896 100644
--- a/src/luarocks/persist.tl
+++ b/src/luarocks/persist.tl
@@ -16,6 +16,7 @@ persist.load_into_table = core.load_into_table
16 16
17local interface Writer 17local interface Writer
18 write: function(self: Writer, data: string) 18 write: function(self: Writer, data: string)
19 buffer: {number | string}
19end 20end
20 21
21local write_table: function(out: Writer, tbl: {number | string: number| string}, level: integer, field_order: util.SortBy<number | string>) 22local write_table: function(out: Writer, tbl: {number | string: number| string}, level: integer, field_order: util.SortBy<number | string>)
@@ -175,7 +176,7 @@ end
175-- @param field_order table: an optional array indicating the order of top-level fields. 176-- @param field_order table: an optional array indicating the order of top-level fields.
176-- @return persisted data as string; or nil and an error message 177-- @return persisted data as string; or nil and an error message
177function persist.save_from_table_to_string(tbl: {number | string: number | string}, field_order: util.SortBy<number | string>): string, string 178function persist.save_from_table_to_string(tbl: {number | string: number | string}, field_order: util.SortBy<number | string>): string, string
178 local out: Writer = {buffer = {}} --! 179 local out: Writer = {buffer = {}}
179 function out:write(data: string) table.insert(self.buffer, data) end 180 function out:write(data: string) table.insert(self.buffer, data) end
180 local ok, err = write_table_as_assignments(out, tbl, field_order) 181 local ok, err = write_table_as_assignments(out, tbl, field_order)
181 if not ok then 182 if not ok then
@@ -193,14 +194,14 @@ end
193-- @param field_order table: an optional array indicating the order of top-level fields. 194-- @param field_order table: an optional array indicating the order of top-level fields.
194-- @return boolean or (nil, string): true if successful, or nil and a 195-- @return boolean or (nil, string): true if successful, or nil and a
195-- message in case of errors. 196-- message in case of errors.
196function persist.save_from_table(filename: string, tbl: {number | string : number | string}, field_order: util.SortBy<number | string>) 197function persist.save_from_table(filename: string, tbl: {number | string : number | string}, field_order: util.SortBy<number | string>): boolean, string
197 local prefix = dir.dir_name(filename) 198 local prefix = dir.dir_name(filename)
198 fs.make_dir(prefix) 199 fs.make_dir(prefix)
199 local out = io.open(filename, "w") 200 local out = io.open(filename, "w")
200 if not out then 201 if not out then
201 return nil, "Cannot create file at "..filename 202 return nil, "Cannot create file at "..filename
202 end 203 end
203 local ok, err = write_table_as_assignments(out, tbl, field_order) 204 local ok, err = write_table_as_assignments(out, tbl, field_order) --! interface problems
204 out:close() 205 out:close()
205 if not ok then 206 if not ok then
206 return nil, err 207 return nil, err
@@ -216,32 +217,32 @@ end
216-- @param tbl table: the table containing the data to be written 217-- @param tbl table: the table containing the data to be written
217-- @return boolean or (nil, string): true if successful, or nil and a 218-- @return boolean or (nil, string): true if successful, or nil and a
218-- message in case of errors. 219-- message in case of errors.
219function persist.save_as_module(filename, tbl) 220function persist.save_as_module(filename: string, tbl: {number | string : number | string}): boolean, string
220 local out = io.open(filename, "w") 221 local out = io.open(filename, "w")
221 if not out then 222 if not out then
222 return nil, "Cannot create file at "..filename 223 return nil, "Cannot create file at "..filename
223 end 224 end
224 write_table_as_table(out, tbl) 225 write_table_as_table(out, tbl) --! interface problems
225 out:close() 226 out:close()
226 return true 227 return true
227end 228end
228 229
229function persist.load_config_file_if_basic(filename, cfg) 230function persist.load_config_file_if_basic(filename: string, cfg): boolean | {number | string : number | string}, string --! cfg type
230 local env = { 231 local env = {
231 home = cfg.home 232 home = cfg.home
232 } 233 }
233 local result, err, errcode = persist.load_into_table(filename, env) 234 local result, _, errcode = persist.load_into_table(filename, env)
234 if errcode == "load" or errcode == "run" then 235 if errcode == "load" or errcode == "run" then
235 -- bad config file or depends on env, so error out 236 -- bad config file or depends on env, so error out
236 return nil, "Could not read existing config file " .. filename 237 return nil, "Could not read existing config file " .. filename
237 end 238 end
238 239
239 local tbl 240 local tbl: {number | string : number | string}
240 if errcode == "open" then 241 if errcode == "open" then
241 -- could not open, maybe file does not exist 242 -- could not open, maybe file does not exist
242 tbl = {} 243 tbl = {}
243 else 244 else
244 tbl = result 245 tbl = result --! strongger definition --? make the load into table generic
245 tbl.home = nil 246 tbl.home = nil
246 end 247 end
247 248
diff --git a/src/luarocks/results.tl b/src/luarocks/results.tl
index 78a46da9..a5bc25fe 100644
--- a/src/luarocks/results.tl
+++ b/src/luarocks/results.tl
@@ -1,5 +1,4 @@
1local record results 1local record results
2
3end 2end
4 3
5local vers = require("luarocks.core.vers") 4local vers = require("luarocks.core.vers")
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 165cb8fa..04865715 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -553,38 +553,6 @@ end
553 553
554 554
555 555
556function util.opts_table(type_name, valid_opts) --! TEMP
557 local opts_mt = {}
558
559 opts_mt.__index = opts_mt
560
561 function opts_mt.type()
562 return type_name
563 end
564
565 return function(opts)
566 for k, v in pairs(opts) do
567 local tv = type(v)
568 if not valid_opts[k] then
569 error("invalid option: "..k)
570 end
571 local vo, optional = valid_opts[k]:match("^(.-)(%??)$")
572 if not (tv == vo or (optional == "?" and tv == nil)) then
573 error("invalid type option: "..k.." - got "..tv..", expected "..vo)
574 end
575 end
576 for k, v in pairs(valid_opts) do
577 if (not v:find("?", 1, true)) and opts[k] == nil then
578 error("missing option: "..k)
579 end
580 end
581 return setmetatable(opts, opts_mt)
582 end
583end
584
585
586
587
588function util.get_rocks_provided(rockspec) 556function util.get_rocks_provided(rockspec)
589 557
590 if not rockspec and cfg.cache.rocks_provided then 558 if not rockspec and cfg.cache.rocks_provided then