Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Treat negative numbers and dashes as values
Browse files Browse the repository at this point in the history
  • Loading branch information
eush77 committed Dec 8, 2014
1 parent 1f486c5 commit 7b2e0a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions nomnom.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ ArgParser.prototype.setOption = function(options, arg, value) {
/* an arg is an item that's actually parsed from the command line
e.g. "-l", "log.txt", or "--logfile=log.txt" */
var Arg = function(str) {
var abbrRegex = /^\-(\w+?)$/,
var abbrRegex = /^\-([a-zA-Z]+?)$/,
fullRegex = /^\-\-(no\-)?(.+?)(?:=(.+))?$/,
valRegex = /^[^\-].*/;
valRegex = /^[^\-].*|^\-[\d.]*$/;

var charMatch = abbrRegex.exec(str),
chars = charMatch && charMatch[1].split("");
Expand Down
16 changes: 14 additions & 2 deletions test/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports.testFlag = function(test) {
exports.testList = function(test) {
var options = parser.parse(["pos0", "pos1", "--list1=val0", "--list2", "val1",
"--list2", "val2", "pos2"]);

test.deepEqual(options.list1, ["val0"]);
test.deepEqual(options.list2, ["val1", "val2"]);
test.deepEqual(options.list3, ["pos1", "pos2"]);
Expand All @@ -63,7 +63,7 @@ exports.testDefault = function(test) {
exports.testTypes = function(test) {
var options = parser.parseArgs(["", "-x", "3.14", "-w", "true", "-q", "120",
"--num1", "4"]);

test.strictEqual(options[0], "");
test.strictEqual(options.x, 3.14);
test.strictEqual(options.w, true);
Expand All @@ -72,4 +72,16 @@ exports.testTypes = function(test) {
test.done();
}

exports.testDash = function(test) {
var options = parser.parseArgs(['--num1', '-']);

test.strictEqual(options.num1, '-');
test.done();
};

exports.testNumbers = function(test) {
var options = parser.parseArgs(['sum', '-1', '2.5', '-3.5', '4']);

test.deepEqual(options.list3, ['-1', '2.5', '-3.5', '4']);
test.done();
};

0 comments on commit 7b2e0a2

Please sign in to comment.