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,21 +150,28 @@ function shell.parse(...)
local params = table.pack(...) local params = table.pack(...)
local args = {} local args = {}
local options = {} local options = {}
local doneWithOptions = false
for i = 1, params.n do for i = 1, params.n do
local param = params[i] local param = params[i]
if type(param) == "string" and unicode.sub(param, 1, 2) == "--" and param ~= "--" then 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 if param:match("%-%-(.-)=") ~= nil then
options[param:match("%-%-(.-)=")] = param:match("=(.*)") options[param:match("%-%-(.-)=")] = param:match("=(.*)")
else else
options[unicode.sub(param, 3)] = true options[unicode.sub(param, 3)] = true
end end
elseif type(param) == "string" and unicode.sub(param, 1, 1) == "-" and param ~= "--" and param ~= "-" then elseif unicode.sub(param, 1, 1) == "-" and param ~= "-" then
for j = 2, unicode.len(param) do for j = 2, unicode.len(param) do
options[unicode.sub(param, j, j)] = true options[unicode.sub(param, j, j)] = true
end end
else else
table.insert(args, param) table.insert(args, param)
end end
else
table.insert(args, param)
end
end end
return args, options return args, options
end end