From 79096e46d653cfbf06970c2a638855c40232adee Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Mon, 29 Jul 2024 19:46:34 +0300 Subject: removing util.opts_table --- src/luarocks/build.lua | 16 ---------------- src/luarocks/cmd/install.lua | 17 ++--------------- src/luarocks/persist.tl | 19 ++++++++++--------- src/luarocks/results.tl | 1 - src/luarocks/util.lua | 32 -------------------------------- 5 files changed, 12 insertions(+), 73 deletions(-) (limited to 'src') 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") local writer = require("luarocks.manif.writer") local deplocks = require("luarocks.deplocks") -build.opts = util.opts_table("build.opts", { --WORK - need_to_fetch = "boolean", - minimal_mode = "boolean", - deps_mode = "string", - build_only_deps = "boolean", - namespace = "string?", - branch = "string?", - verify = "boolean", - check_lua_versions = "boolean", - pin = "boolean", - rebuild = "boolean", - no_install = "boolean" -}) - do --- Write to the current directory the contents of a table, -- where each key is a file name and its value is the file content. @@ -390,8 +376,6 @@ end -- installed rock if succeeded or nil and an error message followed by an error code. function build.build_rockspec(rockspec, opts, cwd) assert(rockspec:type() == "rockspec") - assert(opts:type() == "build.opts") - assert(type(cwd) == "string" or type(cwd) == nil) cwd = cwd or dir.path(".") 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) parser:flag("--sign"):hidden(true) end -install.opts = util.opts_table("install.opts", { --WORK util.opts_table doesn't exist. Make a record - namespace = "string?", - keep = "boolean", - force = "boolean", - force_fast = "boolean", - no_doc = "boolean", - deps_mode = "string", - verify = "boolean", -}) --- Install a binary rock. -- @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 -- installed rock if succeeded or nil and an error message followed by an error code. function install.install_binary_rock(rock_file, opts) assert(type(rock_file) == "string") - assert(opts:type() == "install.opts") local namespace = opts.namespace local deps_mode = opts.deps_mode @@ -156,7 +146,6 @@ end -- followed by an error code. function install.install_binary_rock_deps(rock_file, opts) assert(type(rock_file) == "string") - assert(opts:type() == "install.opts") local name, version, arch = path.parse_name(rock_file) if not name then @@ -190,7 +179,6 @@ function install.install_binary_rock_deps(rock_file, opts) end local function install_rock_file_deps(filename, opts) - assert(opts:type() == "install.opts") local name, version = install.install_binary_rock_deps(filename, opts) if not name then return nil, version end @@ -201,7 +189,6 @@ end local function install_rock_file(filename, opts) assert(type(filename) == "string") - assert(opts:type() == "install.opts") local name, version = install.install_binary_rock(filename, opts) if not name then return nil, version end @@ -237,7 +224,7 @@ function install.command(args) return build.command(args) elseif args.rock:match("%.rock$") then local deps_mode = deps.get_deps_mode(args) - local opts = install.opts({ + local opts = { namespace = args.namespace, keep = not not args.keep, force = not not args.force, @@ -245,7 +232,7 @@ function install.command(args) no_doc = not not args.no_doc, deps_mode = deps_mode, verify = not not args.verify, - }) + } if args.only_deps then return install_rock_file_deps(args.rock, opts) 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 local interface Writer write: function(self: Writer, data: string) + buffer: {number | string} end local write_table: function(out: Writer, tbl: {number | string: number| string}, level: integer, field_order: util.SortBy) @@ -175,7 +176,7 @@ end -- @param field_order table: an optional array indicating the order of top-level fields. -- @return persisted data as string; or nil and an error message function persist.save_from_table_to_string(tbl: {number | string: number | string}, field_order: util.SortBy): string, string - local out: Writer = {buffer = {}} --! + local out: Writer = {buffer = {}} function out:write(data: string) table.insert(self.buffer, data) end local ok, err = write_table_as_assignments(out, tbl, field_order) if not ok then @@ -193,14 +194,14 @@ end -- @param field_order table: an optional array indicating the order of top-level fields. -- @return boolean or (nil, string): true if successful, or nil and a -- message in case of errors. -function persist.save_from_table(filename: string, tbl: {number | string : number | string}, field_order: util.SortBy) +function persist.save_from_table(filename: string, tbl: {number | string : number | string}, field_order: util.SortBy): boolean, string local prefix = dir.dir_name(filename) fs.make_dir(prefix) local out = io.open(filename, "w") if not out then return nil, "Cannot create file at "..filename end - local ok, err = write_table_as_assignments(out, tbl, field_order) + local ok, err = write_table_as_assignments(out, tbl, field_order) --! interface problems out:close() if not ok then return nil, err @@ -216,32 +217,32 @@ end -- @param tbl table: the table containing the data to be written -- @return boolean or (nil, string): true if successful, or nil and a -- message in case of errors. -function persist.save_as_module(filename, tbl) +function persist.save_as_module(filename: string, tbl: {number | string : number | string}): boolean, string local out = io.open(filename, "w") if not out then return nil, "Cannot create file at "..filename end - write_table_as_table(out, tbl) + write_table_as_table(out, tbl) --! interface problems out:close() return true end -function persist.load_config_file_if_basic(filename, cfg) +function persist.load_config_file_if_basic(filename: string, cfg): boolean | {number | string : number | string}, string --! cfg type local env = { home = cfg.home } - local result, err, errcode = persist.load_into_table(filename, env) + local result, _, errcode = persist.load_into_table(filename, env) if errcode == "load" or errcode == "run" then -- bad config file or depends on env, so error out return nil, "Could not read existing config file " .. filename end - local tbl + local tbl: {number | string : number | string} if errcode == "open" then -- could not open, maybe file does not exist tbl = {} else - tbl = result + tbl = result --! strongger definition --? make the load into table generic tbl.home = nil end 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 @@ local record results - end local 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 -function util.opts_table(type_name, valid_opts) --! TEMP - local opts_mt = {} - - opts_mt.__index = opts_mt - - function opts_mt.type() - return type_name - end - - return function(opts) - for k, v in pairs(opts) do - local tv = type(v) - if not valid_opts[k] then - error("invalid option: "..k) - end - local vo, optional = valid_opts[k]:match("^(.-)(%??)$") - if not (tv == vo or (optional == "?" and tv == nil)) then - error("invalid type option: "..k.." - got "..tv..", expected "..vo) - end - end - for k, v in pairs(valid_opts) do - if (not v:find("?", 1, true)) and opts[k] == nil then - error("missing option: "..k) - end - end - return setmetatable(opts, opts_mt) - end -end - - - - function util.get_rocks_provided(rockspec) if not rockspec and cfg.cache.rocks_provided then -- cgit v1.2.3-55-g6feb