Lightweight and easy command-line option parsing.
const kidzboptions = ;const options = kidzboptions;
This is the easiest way to parse options. You pass in a configuration describing the options you want, and get back an object with option values keyed by option name.
--version are automatically added. If specified, kidzboptions will print usage or version information and exit the process with a zero error code.
If the passed options are invalid (say, a string option was not given a value), kidzboptions will print an error & usage information, and exit the process with a non-zero error code.
All configuration properties are optional:
info: a string describing this program, which is printed with the usage text
version: the program version, printed if the
--versionoption is given
options: an object describing your command line options. See below.
positional: an array of strings that will be used to name anonymous (positional) arguments to your program
In the option schema, object keys automatically become the long form of your options. Every option must have a long form. The following properties are supported (all optional).
description: A string to be printed in the usage text to describe this option. Defaults to no description.
type: Can be
"string" to indicate that an option requires a value or
"boolean" to indicate that it does not.
String option values may be passed with the short form
-a value or the long form
--a-long-option=value. Defaults to
Boolean options can be specified multiple times, which will cause the value to be flipped each time it occurs.
short: A single-character string specifying the short option. Defaults to the first character of the long option, unless it conflicts with another option, in which case the option will have no short version.
required: A boolean indicating that an option value must be provided. Only applies to string options. Defaults to
If you need more control over the result of your parsing, this method takes the same arguments as
options but returns a parser that you can call manually with the following functions.
ARGV array and returns the result. The result object has these properties:
help: true if the
--helpoption was specified
version: true if the
--versionoption was specified
errors: an array of strings containing any validation errors
result: The parsed options. This is the same object you get back from
options()if parsing succeeds.
Gets the usage text, generated from the option schema.
Gets the version text, generated from the option schema.