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:
@@ -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 = { }, { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user