Skip to content

Instantly share code, notes, and snippets.

@sinlerdev
Last active February 22, 2023 19:29
Show Gist options
  • Save sinlerdev/a5aacee0f8dbec1bad80b97b7d541ac5 to your computer and use it in GitHub Desktop.
Save sinlerdev/a5aacee0f8dbec1bad80b97b7d541ac5 to your computer and use it in GitHub Desktop.
-- Syntax
-- lune script SUBCOMMAND ==flag value
-- lune scri[t ==flag value SUBCOMMAND
local function parseFlags(arguments: { string })
local result = {}
for index, keyOrValue in arguments do
if keyOrValue:find("==") then
local shouldBeValue = arguments[index + 1]
if shouldBeValue:find("==") then
error(`Value wasn't provided for {keyOrValue}`)
end
result[string.sub(keyOrValue, 3)] = shouldBeValue
end
end
return result
end
local function parse(args: { string })
local result
local onlyFlagTable = {}
for index, value in args do
if not (args[index - 1] or ""):find("==") and not value:find("==") then
result = value
else
table.insert(onlyFlagTable, value)
end
end
return result, parseFlags(onlyFlagTable)
end
return parse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment