[Pkg-javascript-commits] [node-minimist] 01/08: Imported Upstream version 1.1.3
Ross Gammon
ross-guest at moszumanska.debian.org
Wed Aug 19 19:15:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
ross-guest pushed a commit to branch master
in repository node-minimist.
commit 0571f6054f4ec868eb68593db321f92c4f3beaca
Author: Ross Gammon <rossgammon at mail.dk>
Date: Wed Aug 19 20:47:34 2015 +0200
Imported Upstream version 1.1.3
---
.travis.yml | 4 ++++
index.js | 17 ++++++++++++++---
package.json | 2 +-
test/bool.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index cc4dba2..74c57bf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,3 +2,7 @@ language: node_js
node_js:
- "0.8"
- "0.10"
+ - "0.12"
+ - "iojs"
+before_install:
+ - npm install -g npm@~1.4.6
diff --git a/index.js b/index.js
index 185a045..de61285 100644
--- a/index.js
+++ b/index.js
@@ -85,6 +85,12 @@ module.exports = function (args, opts) {
}
}
+ function aliasIsBoolean(key) {
+ return aliases[key].some(function (x) {
+ return flags.bools[x];
+ });
+ }
+
for (var i = 0; i < args.length; i++) {
var arg = args[i];
@@ -93,7 +99,12 @@ module.exports = function (args, opts) {
// 'dotall' regex modifier. See:
// http://stackoverflow.com/a/1068308/13216
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
- setArg(m[1], m[2], arg);
+ var key = m[1];
+ var value = m[2];
+ if (flags.bools[key]) {
+ value = value !== 'false';
+ }
+ setArg(key, value, arg);
}
else if (/^--no-.+/.test(arg)) {
var key = arg.match(/^--no-(.+)/)[1];
@@ -105,7 +116,7 @@ module.exports = function (args, opts) {
if (next !== undefined && !/^-/.test(next)
&& !flags.bools[key]
&& !flags.allBools
- && (aliases[key] ? !flags.bools[aliases[key]] : true)) {
+ && (aliases[key] ? !aliasIsBoolean(key) : true)) {
setArg(key, next, arg);
i++;
}
@@ -150,7 +161,7 @@ module.exports = function (args, opts) {
if (!broken && key !== '-') {
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
&& !flags.bools[key]
- && (aliases[key] ? !flags.bools[aliases[key]] : true)) {
+ && (aliases[key] ? !aliasIsBoolean(key) : true)) {
setArg(key, args[i+1], arg);
i++;
}
diff --git a/package.json b/package.json
index 4247f4d..1271939 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "minimist",
- "version": "1.1.1",
+ "version": "1.1.3",
"description": "parse argument options",
"main": "index.js",
"devDependencies": {
diff --git a/test/bool.js b/test/bool.js
index 749e083..14b0717 100644
--- a/test/bool.js
+++ b/test/bool.js
@@ -80,6 +80,29 @@ test('boolean and alias with options hash', function (t) {
t.end();
});
+test('boolean and alias array with options hash', function (t) {
+ var aliased = [ '-h', 'derp' ];
+ var regular = [ '--herp', 'derp' ];
+ var alt = [ '--harp', 'derp' ];
+ var opts = {
+ alias: { 'h': ['herp', 'harp'] },
+ boolean: 'h'
+ };
+ var aliasedArgv = parse(aliased, opts);
+ var propertyArgv = parse(regular, opts);
+ var altPropertyArgv = parse(alt, opts);
+ var expected = {
+ harp: true,
+ herp: true,
+ h: true,
+ '_': [ 'derp' ]
+ };
+ t.same(aliasedArgv, expected);
+ t.same(propertyArgv, expected);
+ t.same(altPropertyArgv, expected);
+ t.end();
+});
+
test('boolean and alias using explicit true', function (t) {
var aliased = [ '-h', 'true' ];
var regular = [ '--herp', 'true' ];
@@ -117,3 +140,27 @@ test('boolean and --x=true', function(t) {
t.same(parsed.other, 'false');
t.end();
});
+
+test('boolean --boool=true', function (t) {
+ var parsed = parse(['--boool=true'], {
+ default: {
+ boool: false
+ },
+ boolean: ['boool']
+ });
+
+ t.same(parsed.boool, true);
+ t.end();
+});
+
+test('boolean --boool=false', function (t) {
+ var parsed = parse(['--boool=false'], {
+ default: {
+ boool: true
+ },
+ boolean: ['boool']
+ });
+
+ t.same(parsed.boool, false);
+ t.end();
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-minimist.git
More information about the Pkg-javascript-commits
mailing list