Merge pull request #233 from gamax92/master

Modify option parsing to ignore - and --, add support for equal sign
This commit is contained in:
Florian Nücke 2014-04-25 15:08:11 +02:00
commit 9d87cdbcb4
2 changed files with 8 additions and 4 deletions

View File

@ -11,7 +11,7 @@ computer.pushSignal("init") -- so libs know components are initialized.
while true do while true do
require("term").clear() require("term").clear()
io.write(_OSVERSION .. " (" .. math.floor(computer.totalMemory() / 1024) .. "k RAM)\n") io.write(_OSVERSION .. " (" .. math.floor(computer.totalMemory() / 1024) .. "k RAM)\n")
local result, reason = os.execute(os.getenv("SHELL") .. " -") local result, reason = os.execute(os.getenv("SHELL"))
if not result then if not result then
io.stderr:write((tostring(reason) or "unknown error") .. "\n") io.stderr:write((tostring(reason) or "unknown error") .. "\n")
print("Press any key to continue.") print("Press any key to continue.")

View File

@ -152,9 +152,13 @@ function shell.parse(...)
local options = {} local options = {}
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) == "--" then if type(param) == "string" and unicode.sub(param, 1, 2) == "--" and param ~= "--" then
options[unicode.sub(param, 3)] = true if param:match("%-%-(.-)=") ~= nil then
elseif type(param) == "string" and unicode.sub(param, 1, 1) == "-" then options[param:match("%-%-(.-)=")] = param:match("=(.*)")
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 for j = 2, unicode.len(param) do
options[unicode.sub(param, j, j)] = true options[unicode.sub(param, j, j)] = true
end end