Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow cflag style option params, unit test, fixes #174

  • Loading branch information...
commit a8248965b9206f679e71cbb9f3bf46944ef0e5ad 1 parent 38b7adb
@tonylukasavage tonylukasavage authored
Showing with 21 additions and 2 deletions.
  1. +6 −2 index.js
  2. +15 −0 test/test.options.cflags.js
View
8 index.js
@@ -431,11 +431,16 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
Command.prototype.normalize = function(args){
var ret = []
, arg
+ , lastOpt
, index;
for (var i = 0, len = args.length; i < len; ++i) {
arg = args[i];
- if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {
+ i > 0 && (lastOpt = this.optionFor(args[i-1]));
+
+ if (lastOpt && lastOpt.required) {
+ ret.push(arg);
+ } else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {
arg.slice(1).split('').forEach(function(c){
ret.push('-' + c);
});
@@ -544,7 +549,6 @@ Command.prototype.parseOptions = function(argv){
if (option.required) {
arg = argv[++i];
if (null == arg) return this.optionMissingArgument(option);
- if ('-' == arg[0] && '-' != arg) return this.optionMissingArgument(option, arg);
this.emit(option.name(), arg);
// optional arg
} else if (option.optional) {
View
15 test/test.options.cflags.js
@@ -0,0 +1,15 @@
+/**
+ * Module dependencies.
+ */
+
+var program = require('../')
+ , should = require('should');
+
+program
+ .version('0.0.1')
+ .option('-c, --cflags <cflags>', 'pass options/flags to a compiler')
+ .option('-o, --other', 'just some other option');
+
+program.parse(['node', 'test', '--cflags', '-DDEBUG', '-o']);
+program.should.have.property('cflags', '-DDEBUG');
+program.should.have.property('other');
Please sign in to comment.
Something went wrong with that request. Please try again.