From 39a68fd9647c180cba00ff76cc6b53e239060638 Mon Sep 17 00:00:00 2001 From: Seth Fitzsimmons Date: Tue, 27 May 2014 16:17:49 -0700 Subject: [PATCH] If values contain spaces, treat them as values Option names should never contain spaces; values might. This (partially) works around #37, but still prevents individual negative values from being treated as values. --- nomnom.js | 2 +- test/values.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nomnom.js b/nomnom.js index 9a8468c..ec3f998 100644 --- a/nomnom.js +++ b/nomnom.js @@ -487,7 +487,7 @@ ArgParser.prototype.setOption = function(options, arg, value) { Arg = function(str) { var abbrRegex = /^\-(\w+?)$/, fullRegex = /^\-\-(no\-)?(.+?)(?:=(.+))?$/, - valRegex = /^[^\-].*/; + valRegex = /\s|^[^\-].*/; var charMatch = abbrRegex.exec(str), chars = charMatch && charMatch[1].split(""); diff --git a/test/values.js b/test/values.js index 797807e..0e3b1fd 100644 --- a/test/values.js +++ b/test/values.js @@ -72,4 +72,9 @@ exports.testTypes = function(test) { test.done(); } +exports.testValues = function(test) { + var options = parser.parseArgs(["--num1", "-4 4"]); + test.strictEqual(options.num1, "-4 4"); + test.done(); +}