Fixed IRC/VK, added missing system.parseArguments functionality

This commit is contained in:
Igor Timofeev 2019-01-23 21:26:16 +03:00
parent 8e73b7f96d
commit c8352db0e3
3 changed files with 27 additions and 7 deletions

View File

@ -7,6 +7,7 @@ local system = require("System")
local paths = require("Paths")
local system = require("System")
local text = require("Text")
local event = require("Event")
local number = require("Number")
-------------------------------------------------------------------------------

View File

@ -5,7 +5,7 @@ local filesystem = require("Filesystem")
local color = require("Color")
local image = require("Image")
local internet = require("Internet")
local json = require("json")
local json = require("JSON")
local color = require("Color")
local paths = require("Paths")
local system = require("System")

View File

@ -110,13 +110,32 @@ function system.createShortcut(where, forWhat)
end
function system.parseArguments(...)
local arguments, options = {...}, {}
local i = 1
local i, arguments, options, dashes, data, key, value = 1, {...}, {}
while i <= #arguments do
local option = arguments[i]:match("^%-+(.+)")
if option then
options[option] = true
table.remove(arguments, i)
if type(arguments[i]) == "string" then
dashes, data = arguments[i]:match("^(%-+)(.+)")
if dashes then
-- Single dash option
if #dashes == 1 then
for i = 1, unicode.len(data) do
options[unicode.sub(data, i, i)] = true
end
-- Multiple dash option
else
-- Option with key and value
key, value = data:match("^([^=]+)=(.+)")
if key then
options[key] = value
else
options[data] = true
end
end
table.remove(arguments, i)
i = i - 1
end
end
i = i + 1