Skip to content

Commit 617ced5

Browse files
author
James Halliday
committed
docs
1 parent 0b572d8 commit 617ced5

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

example/show.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var subarg = require('../');
2+
var argv = subarg(process.argv.slice(2));
3+
console.log(argv);

readme.markdown

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# subarg
2+
3+
parse arguments with recursive contexts using
4+
[minimist](https://npmjs.org/package/minimist)
5+
6+
This module is useful if you need to pass arguments into a piece of code without
7+
coordinating ahead of time with the main program, like with a plugin system.
8+
9+
# example
10+
11+
``` js
12+
var subarg = require('subarg');
13+
var argv = subarg(process.argv.slice(2));
14+
console.log(argv);
15+
```
16+
17+
Contexts are denoted with square brackets:
18+
19+
```
20+
$ node example/show.js beep --beep [ boop -a 3 ] -n4 --robots [ -x 8 -y 6 ]
21+
{ _: [ 'beep', ']' ],
22+
beep: { _: [ 'boop' ], a: 3 },
23+
n: 4,
24+
robots: '[',
25+
x: 8,
26+
y: 6 }
27+
```
28+
29+
# methods
30+
31+
``` js
32+
var subarg = require('subarg')
33+
```
34+
35+
## var argv = subarg(args, opts)
36+
37+
Parse the arguments array `args`, passing `opts` to
38+
[minimist](https://npmjs.org/package/minimist).
39+
40+
An opening `[` in the `args` array creates a new context and a `]` closes a
41+
context. Contexts may be nested.
42+
43+
# install
44+
45+
With [npm](https://npmjs.org) do:
46+
47+
```
48+
npm install subarg
49+
```
50+
51+
# license
52+
53+
MIT

0 commit comments

Comments
 (0)