init
This commit is contained in:
4
node_modules/subarg/.travis.yml
generated
vendored
Normal file
4
node_modules/subarg/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
18
node_modules/subarg/LICENSE
generated
vendored
Normal file
18
node_modules/subarg/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3
node_modules/subarg/example/show.js
generated
vendored
Normal file
3
node_modules/subarg/example/show.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var subarg = require('../');
|
||||
var argv = subarg(process.argv.slice(2));
|
||||
console.log(argv);
|
35
node_modules/subarg/index.js
generated
vendored
Normal file
35
node_modules/subarg/index.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
var minimist = require('minimist');
|
||||
|
||||
module.exports = function parse (args, opts) {
|
||||
var level = 0, index;
|
||||
var args_ = [];
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (typeof args[i] === 'string' && /^\[/.test(args[i])) {
|
||||
if (level ++ === 0) {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
if (typeof args[i] === 'string' && /\]$/.test(args[i])) {
|
||||
if (-- level > 0) continue;
|
||||
|
||||
var sub = args.slice(index, i + 1);
|
||||
if (typeof sub[0] === 'string') {
|
||||
sub[0] = sub[0].replace(/^\[/, '');
|
||||
}
|
||||
if (sub[0] === '') sub.shift();
|
||||
|
||||
var n = sub.length - 1;
|
||||
if (typeof sub[n] === 'string') {
|
||||
sub[n] = sub[n].replace(/\]$/, '');
|
||||
}
|
||||
if (sub[n] === '') sub.pop();
|
||||
|
||||
args_.push(parse(sub));
|
||||
}
|
||||
else if (level === 0) args_.push(args[i]);
|
||||
}
|
||||
|
||||
var argv = minimist(args_, opts);
|
||||
return argv;
|
||||
};
|
47
node_modules/subarg/package.json
generated
vendored
Normal file
47
node_modules/subarg/package.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "subarg",
|
||||
"version": "1.0.0",
|
||||
"description": "parse arguments with recursive contexts",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"minimist": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tape": "^3.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/subarg.git"
|
||||
},
|
||||
"homepage": "https://github.com/substack/subarg",
|
||||
"keywords": [
|
||||
"argument",
|
||||
"option",
|
||||
"parser",
|
||||
"parsing",
|
||||
"flags",
|
||||
"command-line",
|
||||
"cli",
|
||||
"recursive",
|
||||
"minimist"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT",
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/8..latest",
|
||||
"firefox/16", "firefox/latest", "firefox/nightly",
|
||||
"chrome/22", "chrome/latest", "chrome/canary",
|
||||
"opera/12..latest", "opera/next",
|
||||
"safari/5.1..latest"
|
||||
]
|
||||
}
|
||||
}
|
55
node_modules/subarg/readme.markdown
generated
vendored
Normal file
55
node_modules/subarg/readme.markdown
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
# subarg
|
||||
|
||||
parse arguments with recursive contexts using
|
||||
[minimist](https://npmjs.org/package/minimist)
|
||||
|
||||
[](https://ci.testling.com/substack/subarg)
|
||||
|
||||
[](http://travis-ci.org/substack/subarg)
|
||||
|
||||
This module is useful if you need to pass arguments into a piece of code without
|
||||
coordinating ahead of time with the main program, like with a plugin system.
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var subarg = require('subarg');
|
||||
var argv = subarg(process.argv.slice(2));
|
||||
console.log(argv);
|
||||
```
|
||||
|
||||
Contexts are denoted with square brackets:
|
||||
|
||||
```
|
||||
$ node example/show.js rawr --beep [ boop -a 3 ] -n4 --robots [ -x 8 -y 6 ]
|
||||
{ _: [ 'rawr' ],
|
||||
beep: { _: [ 'boop' ], a: 3 },
|
||||
n: 4,
|
||||
robots: { _: [], x: 8, y: 6 } }
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var subarg = require('subarg')
|
||||
```
|
||||
|
||||
## var argv = subarg(args, opts)
|
||||
|
||||
Parse the arguments array `args`, passing `opts` to
|
||||
[minimist](https://npmjs.org/package/minimist).
|
||||
|
||||
An opening `[` in the `args` array creates a new context and a `]` closes a
|
||||
context. Contexts may be nested.
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install subarg
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
31
node_modules/subarg/test/arg.js
generated
vendored
Normal file
31
node_modules/subarg/test/arg.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var subarg = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('spaced multi sub-args', function (t) {
|
||||
t.plan(2);
|
||||
|
||||
t.deepEqual(
|
||||
subarg('beep -t [ boop -o a.txt -o b.txt -q ] -v'.split(/\s+/)),
|
||||
{
|
||||
_: [ 'beep'],
|
||||
t: {
|
||||
_: [ 'boop' ],
|
||||
o: [ 'a.txt', 'b.txt' ],
|
||||
q: true
|
||||
},
|
||||
v: true
|
||||
}
|
||||
);
|
||||
t.deepEqual(
|
||||
subarg('beep -t [boop -o a.txt -o b.txt -q] -v'.split(/\s+/)),
|
||||
{
|
||||
_: [ 'beep'],
|
||||
t: {
|
||||
_: [ 'boop' ],
|
||||
o: [ 'a.txt', 'b.txt' ],
|
||||
q: true
|
||||
},
|
||||
v: true
|
||||
}
|
||||
);
|
||||
});
|
24
node_modules/subarg/test/recursive.js
generated
vendored
Normal file
24
node_modules/subarg/test/recursive.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
var subarg = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('recursive', function (t) {
|
||||
t.plan(1);
|
||||
|
||||
t.deepEqual(
|
||||
subarg('-a [ -b [ -c [ -d 5 ] ] ] -e 3'.split(/\s+/)),
|
||||
{
|
||||
_: [],
|
||||
a: {
|
||||
_: [],
|
||||
b: {
|
||||
_: [],
|
||||
c: {
|
||||
_: [],
|
||||
d: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
e: 3
|
||||
}
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user