Skip to content

Commit

Permalink
When --no-* is used default to true
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 14, 2011
1 parent f0b757f commit 98f4ca0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Command.prototype.option = function(flags, description, fn){
, option = new Option(flags, description)
, name = option.name();

// when --no-* we default to true
if (false == option.bool) self[name] = true;

// register the option
this.options.push(option);

Expand Down
16 changes: 16 additions & 0 deletions test/test.options.bool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/**
* Module dependencies.
*/

var program = require('../')
, should = require('should');

program
.version('0.0.1')
.option('-p, --pepper', 'add pepper')
.option('-c, --no-cheese', 'remove cheese');

program.parse(['node', 'test', '--pepper']);
program.pepper.should.be.true;
program.cheese.should.be.true;

0 comments on commit 98f4ca0

Please sign in to comment.