Class: module:jsdoc/opts/argparser

module:jsdoc/opts/argparser

A parser to interpret the key-value pairs entered on the command line.

Constructor

new module:jsdoc/opts/argparser()

Create an instance of the parser.
Source:

Methods

addOption(shortName, longName, hasValue, helpText, canHaveMultipleopt, coerceropt) → {this}

Provide information about a legal option.
Parameters:
Name Type Attributes Default Description
shortName character The short name of the option, entered like: -T.
longName string The equivalent long name of the option, entered like: --test.
hasValue boolean Does this option require a value? Like: -t templatename
helpText string A brief description of the option.
canHaveMultiple boolean <optional>
false Set to `true` if the option can be provided more than once.
coercer function <optional>
A function to coerce the given value to a specific type.
Source:
Returns:
Type
this
Example
myParser.addOption('t', 'template', true, 'The path to the template.');
myParser.addOption('h', 'help', false, 'Show the help message.');

help() → {string}

Generate a summary of all the options with corresponding help text.
Source:
Returns:
Type
string

parse(args, defaultsopt) → {Object}

Get the options.
Parameters:
Name Type Attributes Default Description
args Array.<string> An array, like ['-x', 'hello']
defaults Object <optional>
{} An optional collection of default values.
Source:
Returns:
The keys will be the longNames, or the shortName if no longName is defined for that option. The values will be the values provided, or `true` if the option accepts no value.
Type
Object