Permalink
Browse files

Merge pull request #139 from kawanet/work

allow "-" hyphen as an option argument
  • Loading branch information...
2 parents a3b353a + bd191c4 commit fff7cacaf001ad748b96708385fa9398cbb68c40 @tj committed Jun 13, 2013
Showing with 25 additions and 2 deletions.
  1. +2 −2 index.js
  2. +23 −0 test/test.options.hyphen.js
View
4 index.js
@@ -543,12 +543,12 @@ Command.prototype.parseOptions = function(argv){
if (option.required) {
arg = argv[++i];
if (null == arg) return this.optionMissingArgument(option);
- if ('-' == arg[0]) return this.optionMissingArgument(option, arg);
+ if ('-' == arg[0] && '-' != arg) return this.optionMissingArgument(option, arg);
this.emit(option.name(), arg);
// optional arg
} else if (option.optional) {
arg = argv[i+1];
- if (null == arg || '-' == arg[0]) {
+ if (null == arg || ('-' == arg[0] && '-' != arg)) {
arg = null;
} else {
++i;
View
23 test/test.options.hyphen.js
@@ -0,0 +1,23 @@
+/**
+ * Module dependencies.
+ */
+
+var program = require('../')
+ , should = require('should');
+
+function parseRange(str) {
+ return str.split('..').map(Number);
+}
+
+program
+ .version('0.0.1')
+ .option('-a, --alpha <a>', 'hyphen')
+ .option('-b, --bravo <b>', 'hyphen')
+ .option('-c, --charlie <c>', 'hyphen')
+
+program.parse('node test -a - --bravo - --charlie=- - -- -'.split(' '));
+program.alpha.should.equal('-');
+program.bravo.should.equal('-');
+program.charlie.should.equal('-');
+program.args[0].should.equal('-');
+program.args[1].should.equal('-');

0 comments on commit fff7cac

Please sign in to comment.