pax_global_header00006660000000000000000000000064124135567200014517gustar00rootroot0000000000000052 comment=249bde03606850fac7d89d67e79782f56cd41cce subarg-1.0.0/000077500000000000000000000000001241355672000130005ustar00rootroot00000000000000subarg-1.0.0/.travis.yml000066400000000000000000000000601241355672000151050ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" subarg-1.0.0/LICENSE000066400000000000000000000020611241355672000140040ustar00rootroot00000000000000This 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. subarg-1.0.0/example/000077500000000000000000000000001241355672000144335ustar00rootroot00000000000000subarg-1.0.0/example/show.js000066400000000000000000000001321241355672000157450ustar00rootroot00000000000000var subarg = require('../'); var argv = subarg(process.argv.slice(2)); console.log(argv); subarg-1.0.0/index.js000066400000000000000000000020131241355672000144410ustar00rootroot00000000000000var 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; }; subarg-1.0.0/package.json000066400000000000000000000017251241355672000152730ustar00rootroot00000000000000{ "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" ] } } subarg-1.0.0/readme.markdown000066400000000000000000000022621241355672000160030ustar00rootroot00000000000000# subarg parse arguments with recursive contexts using [minimist](https://npmjs.org/package/minimist) [![testling badge](https://ci.testling.com/substack/subarg.png)](https://ci.testling.com/substack/subarg) [![build status](https://secure.travis-ci.org/substack/subarg.png)](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 subarg-1.0.0/test/000077500000000000000000000000001241355672000137575ustar00rootroot00000000000000subarg-1.0.0/test/arg.js000066400000000000000000000013031241355672000150630ustar00rootroot00000000000000var 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 } ); }); subarg-1.0.0/test/recursive.js000066400000000000000000000007461241355672000163330ustar00rootroot00000000000000var 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 } ); });