diff --git a/config.hjson b/config.hjson index 674b25d..90dd549 100644 --- a/config.hjson +++ b/config.hjson @@ -1,5 +1,5 @@ { - version: 0.34.1 + version: 0.34.2 global_modules: false //disables global modules loading (only looks up for modules in cwd) minify: true compress: true diff --git a/lib/eli/cli.lua b/lib/eli/cli.lua index 4bfba09..e3c562d 100644 --- a/lib/eli/cli.lua +++ b/lib/eli/cli.lua @@ -1,4 +1,6 @@ -local _util = require("eli.util") +local util = require"eli.util" + +local cli = {} ---@class CliArg ---#DES 'CliArg.type' @@ -17,29 +19,27 @@ local _util = require("eli.util") ---Parses array of arguments ---@param args string[]|nil ---@return CliArg[] -local function _parse_args(args) - if not _util.is_array(args) then +function cli.parse_args(args) + if not util.is_array(args) then args = arg end - local _argList = {} - if args == nil then return _argList end + local arg_list = {} + if args == nil then return arg_list end for i = 1, #args, 1 do - local _arg = args[i] - if type(_arg) == "string" then - local _cliOption = _arg:match "^-[-]?([^=]*)" - if _cliOption then -- option - local _value = _arg:match("^[^=]*=(.*)") or true - table.insert(_argList, {type = "option", value = _value, id = _cliOption, arg = _arg}) + local arg = args[i] + if type(arg) == "string" then + local cli_option = arg:match"^-[-]?([^=]*)" + if cli_option then -- option + local _value = arg:match"^[^=]*=(.*)" or true + table.insert(arg_list, { type = "option", value = _value, id = cli_option, arg = arg }) else -- command or parameter - table.insert(_argList, {type = "parameter", value = _arg, id = _arg, arg = _arg}) + table.insert(arg_list, { type = "parameter", value = arg, id = arg, arg = arg }) end - elseif type(_arg) == 'table' then -- passthrough pre processed args - table.insert(_argList, _arg) + elseif type(arg) == "table" then -- passthrough pre processed args + table.insert(arg_list, arg) end end - return _argList + return arg_list end -return { - parse_args = _parse_args -} +return cli diff --git a/lib/eli/env.lua b/lib/eli/env.lua index 3006091..41233f6 100644 --- a/lib/eli/env.lua +++ b/lib/eli/env.lua @@ -1,18 +1,18 @@ -local _os = require "os" -local _eenvLoaded, _eenv = pcall(require, "eli.env.extra") +local os = require"os" +local is_loaded, eenv = pcall(require, "eli.env.extra") -local _util = require "eli.util" +local util = require"eli.util" -local _env = { - get_env = _eenvLoaded and _eenv.get_env or _os.getenv, +local env = { + get_env = is_loaded and eenv.get_env or os.getenv, ---#DES env.EENV --- ---@type boolean - EENV = _eenvLoaded + EENV = is_loaded, } -if not _eenvLoaded then - return _env +if not is_loaded then + return env end -return _util.merge_tables(_env, _eenv) +return util.merge_tables(env, eenv) diff --git a/lib/eli/extensions/io.lua b/lib/eli/extensions/io.lua index e30e480..0cd7c1c 100644 --- a/lib/eli/extensions/io.lua +++ b/lib/eli/extensions/io.lua @@ -4,13 +4,15 @@ if not ok then return {} end +local eio = {} + ---#DES 'io.open_fstream' --- ---@param filename string ---@param mode? openmode ---@return EliReadableStream | EliWritableStream | EliRWStream | nil ---@return string? errmsg -local function open_fstream(filename, mode) +function eio.open_fstream(filename, mode) if not ok then error"eli.stream is not available" end @@ -18,6 +20,8 @@ local function open_fstream(filename, mode) return stream_extra.open_fstream(filename, mode) end -return { - open_fstream = open_fstream, -} +function eio.globalize() + io.open_fstream = eio.open_fstream +end + +return eio diff --git a/lib/eli/extensions/string.lua b/lib/eli/extensions/string.lua index 3944c7c..adc0d25 100644 --- a/lib/eli/extensions/string.lua +++ b/lib/eli/extensions/string.lua @@ -1,8 +1,10 @@ +local es = {} + ---#DES string.trim --- ---@param s string ---@return string -local function _trim(s) +function es.trim(s) if type(s) ~= "string" then return s end return s:match"^()%s*$" and "" or s:match"^%s*(.*%S)" end @@ -13,7 +15,7 @@ end ---@param sep string? ---@param trim boolean? ---@return string[] -local function _split(s, sep, trim) +function es.split(s, sep, trim) if type(s) ~= "string" then return s end if sep == nil then sep = "%s" @@ -34,7 +36,7 @@ end ---@param separator string ---@param ... any ---@return string -local function _join(separator, ...) +function es.join(separator, ...) local _result = "" if type(separator) ~= "string" then separator = "" @@ -61,7 +63,7 @@ end ---@param separator string ---@param ...string ---@return string -local function _join_strings(separator, ...) +function es.join_strings(separator, ...) local _tmp = {} local _parts = table.pack(...) if #_parts > 0 and type(_parts[1]) == "table" then @@ -82,7 +84,7 @@ end ---@param format string ---@param data table? ---@return string -local function _interpolate(format, data) +function es.interpolate(format, data) if data == nil then data = _G end if type(data) ~= "table" then data = {} end ---@param w string @@ -99,19 +101,12 @@ local function _interpolate(format, data) return _result end -local function _globalize() - string.split = _split - string.join = _join - string.join_strings = _join_strings - string.trim = _trim - string.interpolate = _interpolate +function es.globalize() + string.split = es.split + string.join = es.join + string.join_strings = es.join_strings + string.trim = es.trim + string.interpolate = es.interpolate end -return { - globalize = _globalize, - split = _split, - join = _join, - join_strings = _join_strings, - trim = _trim, - interpolate = _interpolate, -} +return es