Make shell stop parsing options at --.

This commit is contained in:
Florian Nücke 2014-04-25 15:45:14 +02:00
parent 9d87cdbcb4
commit 54cc679c37

View File

@ -150,17 +150,24 @@ function shell.parse(...)
local params = table.pack(...)
local args = {}
local options = {}
local doneWithOptions = false
for i = 1, params.n do
local param = params[i]
if type(param) == "string" and unicode.sub(param, 1, 2) == "--" and param ~= "--" then
if param:match("%-%-(.-)=") ~= nil then
options[param:match("%-%-(.-)=")] = param:match("=(.*)")
if not doneWithOptions and type(param) == "string" then
if param == "--" then
doneWithOptions = true -- stop processing options at `--`
elseif unicode.sub(param, 1, 2) == "--" then
if param:match("%-%-(.-)=") ~= nil then
options[param:match("%-%-(.-)=")] = param:match("=(.*)")
else
options[unicode.sub(param, 3)] = true
end
elseif unicode.sub(param, 1, 1) == "-" and param ~= "-" then
for j = 2, unicode.len(param) do
options[unicode.sub(param, j, j)] = true
end
else
options[unicode.sub(param, 3)] = true
end
elseif type(param) == "string" and unicode.sub(param, 1, 1) == "-" and param ~= "--" and param ~= "-" then
for j = 2, unicode.len(param) do
options[unicode.sub(param, j, j)] = true
table.insert(args, param)
end
else
table.insert(args, param)