1
0
mirror of https://github.com/kepler155c/opus synced 2025-12-19 06:38:06 +00:00

support open os command line programs

This commit is contained in:
kepler155c@gmail.com
2019-04-07 10:09:47 -04:00
parent 737ac095de
commit 4f9bd8eb0f
9 changed files with 146 additions and 65 deletions

View File

@@ -659,6 +659,37 @@ function Util.wordWrap(str, limit)
return lines
end
-- https://github.com/MightyPirates/OpenComputers
function Util.parse(...)
local params = table.pack(...)
local args = {}
local options = {}
local doneWithOptions = false
for i = 1, params.n do
local param = params[i]
if not doneWithOptions and type(param) == "string" then
if param == "--" then
doneWithOptions = true -- stop processing options at `--`
elseif param:sub(1, 2) == "--" then
local key, value = param:match("%-%-(.-)=(.*)")
if not key then
key, value = param:sub(3), true
end
options[key] = value
elseif param:sub(1, 1) == "-" and param ~= "-" then
for j = 2, string.len(param) do
options[string.sub(param, j, j)] = true
end
else
table.insert(args, param)
end
else
table.insert(args, param)
end
end
return args, options
end
function Util.args(arg)
local options, args = { }, { }