Oopt
Parsing commanl-line arguments in style of old good getopt with no extras. For geeks and minimalists only. Only configuration is standart optstring
(something like 'ab:c
') and result is an object with 'options', 'arguments' and 'operands'.
If no bugs, it ought to be pure getopt, that is described in The Open Group Base Specifications Issue 7 (aka IEEE Std 1003.1, 2013 Edition):
The getopt() function is a command-line parser that shall follow Utility Syntax Guidelines 3, 4, 5, 6, 7, 9, and 10 in XBD Utility Syntax Guidelines.
Main intention was to make utility, which passed tests, that describe those XBD Utility Syntax Guidelines:
Guideline 3: Each option name should be a single alphanumeric character (the alnum character classification) from the portable character set. The -W (capital-W) option shall be reserved for vendor options. Multi-digit options should not be allowed.
Guideline 4: All options should be preceded by the '-' delimiter character.
Guideline 5: One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter.
Guideline 6: Each option and option-argument should be a separate argument, except as noted in Utility Argument Syntax, item (2).
Guideline 7: Option-arguments should not be optional.
Guideline 9: All options should precede operands on the command line.
Guideline 10: The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
If something in oopt
works not like in Guidelines - that's a bug. Feel free to make issue or pull request.
Install
npm install oopt
Tests
$ npm test
Example
//app.jsvar oopt = ;console;
$ node app.js
More examples in tests.
License
MIT