forked from trentm/node-cmdln
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-opts.js
executable file
·38 lines (34 loc) · 1.07 KB
/
main-opts.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
#!/usr/bin/env node
/*
* A CLI to test out `cmdln.main()` opts.
*/
var p = console.log;
var util = require('util');
var cmdln = require('../../lib/cmdln');
function CLI() {
cmdln.Cmdln.call(this, {
name: 'main-opts',
desc: 'Test out cmdln.main() options.',
options: [
{name: 'verbose', type: 'bool',
help: 'See this.showErrStack=true to test that.'},
]
});
}
util.inherits(CLI, cmdln.Cmdln);
CLI.prototype.init = function (opts, args, callback) {
if (opts.verbose) {
this.showErrStack = true;
}
cmdln.Cmdln.prototype.init.apply(this, arguments);
};
if (require.main === module) {
cmdln.main(new CLI(), {
argv: (process.env.MAIN_OPTS_ARGV
? process.env.MAIN_OPTS_ARGV.split(',') : undefined),
showNoCommandErr: Boolean(process.env.MAIN_OPTS_SHOW_NO_COMMAND_ERR),
showCode: Boolean(process.env.MAIN_OPTS_SHOW_CODE),
showErrStack: (process.env.MAIN_OPTS_SHOW_ERR_STACK
? Boolean(process.env.MAIN_OPTS_SHOW_ERR_STACK) : undefined)
});
}