Skip to content

Commit f5abcdb

Browse files
authored
Merge pull request #728 from sorohan/master
Fixes issue #727: Passing empty string for option on command is set to undefined
2 parents d5ac793 + 06451e3 commit f5abcdb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ Command.prototype.parseOptions = function(argv) {
747747
// If the next argument looks like it might be
748748
// an argument for this option, we pass it on.
749749
// If it isn't, then it'll simply be ignored
750-
if (argv[i + 1] && argv[i + 1][0] !== '-') {
750+
if ((i + 1) < argv.length && argv[i + 1][0] !== '-') {
751751
unknownOptions.push(argv[++i]);
752752
}
753753
continue;
@@ -855,8 +855,8 @@ Command.prototype.version = function(str, flags) {
855855
if (arguments.length === 0) return this._version;
856856
this._version = str;
857857
flags = flags || '-V, --version';
858-
var longOptIndex = flags.indexOf('--')
859-
this._versionOptionName = ~longOptIndex ? flags.substr(longOptIndex + 2) : 'version'
858+
var longOptIndex = flags.indexOf('--');
859+
this._versionOptionName = ~longOptIndex ? flags.substr(longOptIndex + 2) : 'version';
860860
this.option(flags, 'output the version number');
861861
this.on('option:' + this._versionOptionName, function() {
862862
process.stdout.write(str + '\n');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Module dependencies.
3+
*/
4+
5+
var program = require('../')
6+
, should = require('should');
7+
8+
var val = "some cheese"
9+
program
10+
.name('test')
11+
.command('mycommand')
12+
.option('-c, --cheese [type]', 'optionally specify the type of cheese')
13+
.action(function(cmd) {
14+
val = cmd.cheese;
15+
});
16+
17+
program.parse(['node', 'test', 'mycommand', '--cheese', '']);
18+
19+
val.should.equal('');
20+

0 commit comments

Comments
 (0)