-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathhelp.js
More file actions
40 lines (35 loc) · 942 Bytes
/
Copy pathhelp.js
File metadata and controls
40 lines (35 loc) · 942 Bytes
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
#!/usr/bin/env node
/*
* A small example using dashdash for option processing, with generated
* help output. See "hello.js" for the smallest usage example.
*/
var dashdash = require('../lib/dashdash');
var options = [
{
names: ['verbose', 'v'],
type: 'bool',
help: 'More verbose output.'
},
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
}
];
// We'll use this `parser` to parse and to generate help output.
var parser = dashdash.createParser({options: options});
try {
var opts = parser.parse(process.argv);
} catch (e) {
console.error('help: error: %s', e.message);
process.exit(1);
}
// Use `parser.help()` for formatted options help.
if (opts.help) {
var help = parser.help().trimRight();
console.log('usage: node help.js [OPTIONS]\n'
+ 'options:\n'
+ help);
process.exit(0);
}
// ...