[Pkg-javascript-commits] [node-subarg] 02/17: implementation is nearly there

Bastien Roucariès rouca at moszumanska.debian.org
Fri Aug 25 19:28:11 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-subarg.

commit 704017d623d4445e35929d04ffc77e385869cdc7
Author: James Halliday <mail at substack.net>
Date:   Sat Feb 8 19:50:48 2014 -0800

    implementation is nearly there
---
 index.js    | 19 ++++++++++++++++++-
 test/arg.js |  4 ++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index a84b000..5f60112 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,23 @@
 var minimist = require('minimist');
 
-module.exports = function (args, opts) {
+module.exports = function parse (args, opts) {
+    var inside = false, index;
+    for (var i = 0; i < args.length; i++) {
+        if (/^\[/.test(args[i])) {
+            inside = true;
+            index = i;
+        }
+        if (inside && /\]$/.test(args[i])) {
+            var sub = args.slice(index, i);
+            sub[0] = sub[0].replace(/^\[/, '');
+            sub[sub.length-1] = sub[sub.length-1].replace(/\[$/, '');
+            
+            args.splice(index, i, parse(sub));
+            
+            inside = false;
+        }
+    }
+    
     var argv = minimist(args, opts);
     return argv;
 };
diff --git a/test/arg.js b/test/arg.js
index d275168..d6f91ba 100644
--- a/test/arg.js
+++ b/test/arg.js
@@ -5,7 +5,7 @@ test('spaced multi sub-args', function (t) {
     t.plan(2);
     
     t.deepEqual(
-        subarg('beep -t [ boop -o a.txt -o b.txt -q ] -v'),
+        subarg('beep -t [ boop -o a.txt -o b.txt -q ] -v'.split(/\s+/)),
         {
             _: [ 'beep'],
             t: {
@@ -17,7 +17,7 @@ test('spaced multi sub-args', function (t) {
         }
     );
     t.deepEqual(
-        subarg('beep -t [boop -o a.txt -o b.txt -q] -v'),
+        subarg('beep -t [boop -o a.txt -o b.txt -q] -v'.split(/\s+/)),
         {
             _: [ 'beep'],
             t: {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-subarg.git



More information about the Pkg-javascript-commits mailing list