substack/node-optimist — pull request #89 by Chevex (2013-03-15 17:46:36+00:00)
Title: Allow the user to pass in a string instead of an array, and let optimist parse it into an array.

I wrote a little expression to parse a string the way it would be parsed into process.argv from the command line. I needed this for a project but this felt like a feature that would be nice for optimist to have itself.

Now you can simply do:

var result = require('optimist')('-abc -m "some message" --verbose hello there!).argv;
console.log(result);

and get back the expected result

{ _: ['hello', 'there!'],
'$0': 'cwd\app.js',
a: true,
b: true,
c: true,
m: 'some message',
verbose: true }