Usage:
table or nil getopt.init(string name, string programDescription, table optionsTable, table args)
returns table (possibly empty) if there was arguments, returns nil if asked for help
Example:
local tbl = getopt.init("colortext", "Prints text with color", optionsTable, { ... })
if tbl ~= nil then
--Your code
end
Option table (second argument for getopt.init) format:
local optionsTable = {
["color"] = {"Should it be colored", "c", nil},
["number"] = {"How many times should it print", "n", "num"},
}
Produces:
Argument "--color", can be shortened as "-c", boolean (exists or not)
Argument "--number", can be shortened as "-n", has value "num"
They wll be accessible as:
tbl["color"] #for argument "--color"
tbl["number"] #for argument "--number"
shortened options will still return the same variables.
Please note that "--help" or "-h" is a hardcoded option that automatically generates help (and returns nil on getopt.init)
Extra arguments without options:
Example:
program.lua a b c d
will return:
tbl["opt-1 to 4"] = "a to d" #opt meaning optional
Downloads:
[indent=1]os.loadAPI-able version: (Examples at the end)[/indent]
[indent=2]pastebin: aLcLbJsA[/indent]
[indent=2]admipaste: 7439f8ffabdffc4[/indent]
[indent=2]packman: admicos/getopt[/indent]
[indent=1]dofile/inline-able/luapp version:[/indent]
[indent=2]pastebin: VyGBMX1d[/indent]
[indent=2]packman: admicos/luapp-includes-getopt[/indent]
[indent=2](installs to /etc/luapp/include/getopt.inc which can be used like: –pp:include getopt.inc inside luapp.)[/indent]