Posted 24 February 2019 - 09:03 PM
This code snippet will allow your programs to interpret arguments much like a Linux command would!
https://raw.githubus...r/argparser.lua
Using this, your program can have arguments like:
Example (in progdor2):
False means that it's boolean, otherwise it's "string" or "number".
(…) is then ran through the parsing function, and any errors are logged in argErrors.
https://raw.githubus...r/argparser.lua
Using this, your program can have arguments like:
program.lua -s -c 2 -b Spaghet mamamia ravioli
Example (in progdor2):
Spoiler
This declares which arguments are accepted as flags, and also what type they accept.False means that it's boolean, otherwise it's "string" or "number".
local argData = {
["-pb"] = "string", -- pastebin get
["-dd"] = "string", -- direct URL download
["-m"] = "string", -- specify main file
["-PB"] = false, -- pastebin upload
["-e"] = false, -- automatic self-extractor
["-s"] = false, -- silent
["-a"] = false, -- use as API with require, also makes silent
["-c"] = false, -- use CCA compression
["-h"] = false, -- show help
["-i"] = false, -- inspect mode
}
(…) is then ran through the parsing function, and any errors are logged in argErrors.
local argList, argErrors = interpretArgs({...}, argData)
if #argErrors > 0 then
local errList = ""
for k,v in pairs(argErrors) do
if k ~= 1 then
errList = errList .. "\"" .. k .. "\": " .. v .. "; "
end
error(errList:sub(1, -2))
end
end
local pastebinGet = argList["-pb"] -- string, pastebin code
local directDownload = argList["-dd"] -- string, download URL
local mainFile = argList["-m"] -- string, main executable file
local pastebinUpload = argList["-PB"] -- boolean
local selfExtractor = argList["-e"] -- boolean
local silent = argList["-s"] -- boolean
local useCompression = argList["-c"] -- boolean
local justOverwrite = argList["-o"] -- boolean
Edited on 24 February 2019 - 08:03 PM