Skip to content

Commit

Permalink
fixed: missing io.open_fstream
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Sep 26, 2024
1 parent 445c794 commit 8b3de96
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion config.hjson
Original file line number Diff line number Diff line change
@@ -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
Expand Down
36 changes: 18 additions & 18 deletions lib/eli/cli.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local _util = require("eli.util")
local util = require"eli.util"

local cli = {}

---@class CliArg
---#DES 'CliArg.type'
Expand All @@ -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
18 changes: 9 additions & 9 deletions lib/eli/env.lua
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 8 additions & 4 deletions lib/eli/extensions/io.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ 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

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
33 changes: 14 additions & 19 deletions lib/eli/extensions/string.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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 = ""
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 8b3de96

Please sign in to comment.