visionmedia/commander.js — pull request #65 by alsonkemp (2012-06-19 00:13:10+00:00)
Title: Adding parsedOptions

Hey,
Thanks for Commander. Made adding option parsing to a utility a breeze.

One issue we've had is that it's difficult to distinguish parsed-options from other-stuff in the program object. In particular, I want to be able to do _.keys(program.options) in order to get a simple list of options. e.g. I only want to see that 'keyword' was parsed, but the program object has a bunch of other stuff making it difficult to pick out the :

{ commands: [],
options:
[ { flags: '-V, --version', required: 0, optional: 0, bool: true, short: '-V', long: '--version', description: 'output the version number' },,
args: [],
name: 'main.coffee',
Command: [Function: Command],
Option: [Function: Option],
_version: '0.0.1',
_events: { version: [ [Function], [Function] ],...},
rawArgs: [ 'coffee',...],
keyword: 'game' }

This pull request adds a .parsedOptions properties that contains only the options parsed from the command line. This way, properties can be accessed as program.keyword or program.parsedOptions.keyword, and my _.keys(program.parsedOptions) will work fine.