Skip to content

Commit

Permalink
Merge pull request tj#23 from felixge/long-only-flags-with-values
Browse files Browse the repository at this point in the history
Fix: Long-only flags would not take values
  • Loading branch information
tj committed Nov 1, 2011
2 parents d3deb36 + 9e8f3b2 commit 6480233
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Option(flags, description) {
this.optional = ~flags.indexOf('[');
this.bool = !~flags.indexOf('-no-');
flags = flags.split(/[ ,|]+/);
if (flags.length > 1) this.short = flags.shift();
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
this.long = flags.shift();
this.description = description;
}
Expand Down
13 changes: 13 additions & 0 deletions test/test.options.large-only-with-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Module dependencies.
*/

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

program
.version('0.0.1')
.option('--longflag [value]', 'A long only flag with a value');

program.parse(['node', 'test', '--longflag', 'something']);
program.longflag.should.equal('something');

0 comments on commit 6480233

Please sign in to comment.