dnsjit.lib.getopt(3)

πŸ“¦
version 1.5.1 Β· 5 versions
, in epel 10, epel 9, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

πŸ’– dnsjit.lib.getopt β€” the manual page, but make it slay πŸ’–

okay bestie, welcome to dnsjit.lib.getopt(3) from the Library Functions Manual πŸŽ€ this is the little Lua module that handles your command line arguments for you, and honestly? it ate.


✨ NAME ✨

dnsjit.lib.getopt β€” parse and handle arguments 🫢


🌸 SYNOPSIS 🌸

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"))

like… look at her. iconic behavior fr fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is a "getopt long" implementation, which is a fancy way of saying: it handles your command line arguments and prints a cute usage message when someone messes up. lowkey a whole package.

an option is made of up these five things:

  1. the short name (just one character, okay? one. single. character.)
  2. the long name
  3. the default value β€” and plot twist, the default value is also what defines the type πŸ‘‘
  4. the help text
  5. the extensions

and heads up: options are required by default, so if you want them optional you gotta go check the extensions section. no cap.

the Lua types you're allowed to use are boolean, string, and number. that's the whole guest list.

the extensions available are:

  • ? β€” makes the option optional ✨ (she's flexible, she can show up or not, no pressure)
  • * β€” for string and number options this makes it possible to specify it multiple times, and all the values get returned in a table πŸ“š
  • + β€” for number options this acts as a counter increaser; the value will be the default value + 1 for each time the option is given πŸ”₯
also!!! -h and --help are automatically added, unless the option --help is already defined. so don't be weird about it, it's handled πŸ’–

πŸŽ€ Attributes πŸŽ€

  • left β€” a table containing the arguments left over after parsing, same thing that parse() returns. the leftovers. the afterparty 🫢
  • usage_desc β€” a string that describes the usage of the program. if you don't set it, the default is " program [options...] " (yes, with the spaces, that's just her vibe)

πŸ’œ Functions πŸ’œ

  • Getopt.new(args) β€” create a new Getopt object. args is a table of tables, and each inner table specifies the options available. every entry gets unpacked and sent straight to Getopt:add(). it's giving assembly line but make it cute πŸ’…
  • Getopt:log() β€” return the Log object so you can control logging for this instance or module πŸ“
  • Getopt:add(short, long, default, help, extensions) β€” add an option. that's it, that's the function πŸŽ€
  • Getopt:usage() β€” print the usage. go off bestie πŸ“’
  • Getopt:parse(args, startn) β€” parse the options! if args isn't specified or is nil, then the global arg gets used. if startn is given, it'll start parsing arguments in the table from that position. the default position to start at is 2 for dnsjit β€” go look at dnsjit.core(3) if you wanna know why πŸ‘€
  • Getopt:val(name) β€” return the value of an option. the moment of truth ✨

🌈 SEE ALSO 🌈

dnsjit.core(3) β€” go read her too, she's part of the lore πŸ’–


πŸ‘‘ AUTHORS and CONTRIBUTORS πŸ‘‘

the legends who made this happen:

  • Jerry LundstrΓΆm (DNS-OARC)
  • TomΓ‘Ε‘ KΕ™Γ­ΕΎek (CZ.NIC)
  • Petr Ε paček (ISC)

Maintained by DNS-OARC 🫢

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

absolute icons, all of them. periodt. πŸ’…


πŸ’€ BUGS πŸ’€

found a bug? got a feature request? don't suffer in silence, bestie:

https://codeberg.org/DNS-OARC/dnsjit/issues

got a question and need help? hit up:

admin@dns-oarc.net

they're nice, they won't bite πŸ₯Ί


and that's the whole page!! this was dnsjit.lib.getopt(3) from dnsjit version 1.5.1, dated dnsjit.lib.getopt(3) in the footer, and honestly she understood the assignment πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά no notes, mwah 😘