node package manager


Command line options parser, it accepts options starting with -- and a string of any length and can associate to it a shortcut which will be a letter preceded by one - only. many shortcuts can be bounded after a single dash to form somethign like -abcde where a b c d e are shortcuts for command line options. options are by default optional but they may be set as mandatory, options don't have an expected value by default but they can be set to have one. The settings for the possible options are passed to the constructor as an array of js objects.

This class has been created in a couple of hours...maybe less, so it has not been designed properly, however I needed it so here the module for anybody to "enjoy". This is a class which provides features similar to PHP getops, the main class just needs a list of expected parametersas an array of objects. The list of options will look like [ { command : "user", shortcut : "u", hasValue : true }, { command : "password", shortcut : "p", hasValue : true }, ]

The only mandatory key is "command" which is the name of the option and will be parsed when called preceeded by -- so for example we can have

node myfile.js --user john

and the class will parse the pair "--user john" as the option user whith value john. Shortcut is an optional paraeter and allows to define a single character shorten version of the option, for example "u" so that we can rewrite the above example as:

node myfile.js -u john

multiple shortcut may be bound so we can write -adu if we've got a, u and d as valid shortcuts of valid options. The only constrainnt is that if an option expects a value it can't be in the middle of a series of shortcuts. If a and d are shortcuts not expecting a value and u is expecting a value, it is valid to write:

node myfile.js -adu john

but is not valid to do: node myfile.js -aud john

as john is refering to the last of the shortcuts