-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathoption-groups.js
43 lines (38 loc) · 1.11 KB
/
option-groups.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
/*
* An example using option group headings
* <https://github.com/trentm/node-dashdash#option-group-headings>
* To see the help output:
*
* node option-groups.js --help
*/
var dashdash = require('../lib/dashdash');
// Specify the options. Minimally `name` (or `names`) and `type`
// must be given for each.
var options = [
{ names: [ 'not-in-group', 'g' ], type: 'string' },
{ group: 'first group' },
{ names: [ 'first-one', 'f' ], type: 'bool' },
{ names: [ 'first-two', 'F' ], type: 'string' },
{ group: 'empty group' },
{ group: 'second group' },
{ names: [ 'second-one', 's' ], type: 'bool' },
{ names: [ 'help', 'h' ], type: 'bool' },
];
var parser = dashdash.createParser({options: options});
try {
var opts = parser.parse(process.argv);
} catch (e) {
console.error('foo: error: %s', e.message);
process.exit(1);
}
if (opts.help) {
var help = parser.help({includeEnv: true}).trimRight();
console.log(
'usage:\n'
+ ' node option-groups.js [<options>]\n'
+ 'options:\n'
+ help);
process.exit(0);
}
// ...