Parsers
Parsers for various kinds of command-line options.
Different programs will need to take all sorts of different kinds
of options. For instance:
- ssh takes a port number between 0 and 65535,
- svn takes a revision number that can be a natural or a
special word like HEAD, BASE, or PREV,
- wget takes a URL,
- mail takes an email address, and so on.
There's no way for getopt to anticipate and support everything that
every program might want, so instead we use a table-driven approach that you
can extend with custom parsers for your types.
Now, out of the box we do at least provide parsers for basic options like
--verbose, --username jared, --level=100000, and so forth.
But when these aren't good enough, e.g., because you want to have stronger
type requirements on your arguments structure, you can add your own custom-parser functions and plug them in.
Subtopics
- Custom-parser
- How to write custom argument-parsing functions.
- Parse-nat
- Parser for options that require a natp argument, e.g.,
--tabsize or -O, etc.
- Parse-plain
- Parser for plain, argument-free options that are off by default and
must be explicitly enabled, e.g., --verbose or --force.
- Parse-string
- Parser for options that require an argument, but where any arbitrary
string will do, e.g., --username or --eval.
- Parse-pos
- Parser for options that require a posp argument, e.g.,
--block-size or --line-number.
- Defparser
- Register a new argument-parsing function with getopt.