Last active
February 22, 2023 19:29
-
-
Save sinlerdev/a5aacee0f8dbec1bad80b97b7d541ac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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