Optimist Fork With Five Months of Updates Rolled In

Optimist Fork With Five Months of Updates Rolled In

Optimist is a popular node module used to turn an array of arguments into a JavaScript hash making it really easy to access supplied options from the command line. The author of optimist, Substack, maintains over 300 modules on npm. Rather than complain about the lack of updates to optimist I decided I'd just pick up the torch and maintain a proper fork.

One of the things I added was a resetOptions function. Optimist was the reason I had to figure out how to "uncache" modules after they've been required. If you define options with optimist after you load it there is no way to undefine them.


After calling the above anytime the option "foo" is found in the supplied args optimist now assumes it's value is a string, but I needed to redefine options without restarting the node process and re-requiring optimist. With my resetOptions function in yargs I was able to turn this:

for (var key in require.cache)
	if (key.match(/optimist\\index\.js$/))
		delete require.cache[key];

// Require here after module cache has been cleared.
var optimist = require('optimist');

into this:


There are lots of other abilities rolled in that optimist doesn't have as well, such as the ability to count booleans. There are quite a few other additions too and they can all be found in the README.

For a laugh compare READMEs between optimist and yargs :P