[Pkg-javascript-commits] [node-optimist] 07/33: Imported Upstream version 0.5.0
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Fri Feb 27 23:21:46 UTC 2015
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository node-optimist.
commit 861e59053ecff9790b454d6a7b4e2deca402af50
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Fri Feb 27 20:00:31 2015 +0100
Imported Upstream version 0.5.0
---
index.js | 12 +++++++++---
package.json | 2 +-
test/dash.js | 31 +++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/index.js b/index.js
index f6c6e22..7d44ad4 100644
--- a/index.js
+++ b/index.js
@@ -361,6 +361,12 @@ function Argv (args, cwd) {
var broken = false;
for (var j = 0; j < letters.length; j++) {
var next = arg.slice(j+2);
+
+ if (next === '-') {
+ setArg(letters[j], next)
+ continue;
+ }
+
if (/[A-Za-z]/.test(letters[j])
&& /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
setArg(letters[j], next);
@@ -377,10 +383,10 @@ function Argv (args, cwd) {
}
}
- if (!broken) {
- var key = arg.slice(-1)[0];
+ var key = arg.slice(-1)[0];
+ if (!broken && key !== '-') {
- if (args[i+1] && !args[i+1].match(/^-/)
+ if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
&& !flags.bools[key]
&& (aliases[key] ? !flags.bools[aliases[key]] : true)) {
setArg(key, args[i+1]);
diff --git a/package.json b/package.json
index 0a03509..ac0eeac 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name" : "optimist",
- "version" : "0.4.0",
+ "version" : "0.5.0",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"main" : "./index.js",
"dependencies" : {
diff --git a/test/dash.js b/test/dash.js
new file mode 100644
index 0000000..af8ed6f
--- /dev/null
+++ b/test/dash.js
@@ -0,0 +1,31 @@
+var optimist = require('../index');
+var test = require('tap').test;
+
+test('-', function (t) {
+ t.plan(5);
+ t.deepEqual(
+ fix(optimist.parse([ '-n', '-' ])),
+ { n: '-', _: [] }
+ );
+ t.deepEqual(
+ fix(optimist.parse([ '-' ])),
+ { _: [ '-' ] }
+ );
+ t.deepEqual(
+ fix(optimist.parse([ '-f-' ])),
+ { f: '-', _: [] }
+ );
+ t.deepEqual(
+ fix(optimist([ '-b', '-' ]).boolean('b').argv),
+ { b: true, _: [ '-' ] }
+ );
+ t.deepEqual(
+ fix(optimist([ '-s', '-' ]).string('s').argv),
+ { s: '-', _: [] }
+ );
+});
+
+function fix (obj) {
+ delete obj.$0;
+ return obj;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-optimist.git
More information about the Pkg-javascript-commits
mailing list