Module ringo/args
A parser for command line options. This parser supports various option formats:
-a -b -c (multiple short options) -abc (multiple short options combined into one) -a value (short option with value) -avalue (alternative short option with value) --option value (long option with value) --option=value (alternative long option with value)
Parser ()
Create a new command line option parser.
Parser.prototype. addOption (shortName, longName, argument, helpText)
Add an option to the parser.
Parameters
String | shortName | the short option name (without leading hyphen) |
String | longName | the long option name (without leading hyphens) |
String | argument | the name of the argument if the option requires one, or null |
String | helpText | the help text to display for the option |
Returns
Object | this parser for chained invocation |
Parser.prototype. help ()
Get help text for the parser's options suitable for display in command line scripts.
Returns
String | a string explaining the parser's options |
Parser.prototype. parse (args, result)
Parse an arguments array into an option object. If a long option name is defined, it is converted to camelCase and used as property name. Otherwise, the short option name is used as property name.
Passing an result object as second argument is a convenient way to define default options:
Example
parser.parse(system.args, {myOption: "defaultValue"});
Parameters
Array | args | the argument array. Matching options are removed. |
Object | result | optional result object. If undefined, a new Object is created. |
Returns
Object | the result object |