DOKK / manpages / debian 12 / dnsjit / dnsjit.lib.getopt.3.en
dnsjit.lib.getopt(3) Library Functions Manual dnsjit.lib.getopt(3)

dnsjit.lib.getopt - Parse and handle arguments


local getopt = require("dnsjit.lib.getopt").new({
{ "v", "verbose", 0, "Enable verbosity", "?+" },
{ nil, "host", "localhost", "Set host", "?" },
{ "p", nil, 53, "Set port", "?" },
})


local left = getopt:parse()


print("host", getopt:val("host"))
print("port", getopt:val("p"))

A "getopt long" implementation to easily handle command line arguments and display usage. An option is the short name (one character), long name, default value (which also defines the type), help text and extensions. Options are by default required, see extensions to change this.

The Lua types allowed are boolean, string, number.

The extensions available are:

?
Make the option optional.
*
For string and number options this make it possible to specified it multiple times and all values will be returned in a table.
+
For number options this will act as an counter increaser, the value will be the default value + 1 for each time the option is given.

Option -h and --help are automatically added if the option --help is not already defined.

A table that contains the arguments left after parsing, same as returned by parse().
A string that describes the usage of the program, if not set then the default will be " program [options...] ".

Create a new Getopt object. args is a table with tables that specifies the options available. Each entry is unpacked and sent to Getopt:add().
Return the Log object to control logging of this instance or module.
Add an option.
Print the usage.
Parse the options. If args is not specified or nil then the global arg is used. If startn is given, it will start parsing arguments in the table from that position. The default position to start at is 2 for dnsjit, see dnsjit.core(3).
Return the value of an option.

dnsjit.core(3)

Jerry Lundström (DNS-OARC), Tomáš Křížek (CZ.NIC), Petr Špaček (ISC)

Maintained by DNS-OARC

https://www.dns-oarc.net/

For issues and feature requests please use:

https://github.com/DNS-OARC/dnsjit/issues

For question and help please use:

admin@dns-oarc.net
1.2.3 dnsjit