node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org ยป

cl-options

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