From 11fbe6864a7dd03f7c18fb07bcaa73ab3c1a1039 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 9 Jun 2015 13:16:43 +0200 Subject: [PATCH] add support for #66; in *theory* it was already partly there in the 'full' option regex, but the `--no-option` vs. `--option` doesn't seem to be checked thoroughly yet. --- nomnom.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nomnom.js b/nomnom.js index a22b8b4..9be72ec 100644 --- a/nomnom.js +++ b/nomnom.js @@ -482,9 +482,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" */ + e.g. "-l", "-l+", "log.txt", or "--logfile=log.txt" */ var Arg = function (str) { - var abbrRegex = /^\-(\w+?)$/, + var abbrRegex = /^\-(\w+?)([+-]?)$/, fullRegex = /^\-\-(no\-)?(.+?)(?:=(.+))?$/, valRegex = /^[^\-].*/; @@ -502,6 +502,10 @@ var Arg = function (str) { else if (full) { value = fullMatch[1] ? false : fullMatch[3]; } + else if (chars && chars.length === 1) { + // Only allow `-v-` or `-v+` when option `-v` is alone. Do *not* allow `-cfv-` or `-cfv+`! + value = charMatch[2] ? charMatch[2] === '+' : undefined; + } return { str: str,