1 | #!/usr/bin/env node
|
2 | 'use strict';
|
3 |
|
4 | /* eslint-env node */
|
5 |
|
6 | /*
|
7 | * Dependencies.
|
8 | */
|
9 |
|
10 | var cli = require('../lib/cli');
|
11 |
|
12 | /*
|
13 | * Methods.
|
14 | */
|
15 |
|
16 | var stderr = process.stderr;
|
17 | var argv = process.argv;
|
18 |
|
19 | /*
|
20 | * Constants.
|
21 | */
|
22 |
|
23 | var exitStatus = 0;
|
24 |
|
25 | /**
|
26 | * Failure handler.
|
27 | *
|
28 | * @param {Error?} exception
|
29 | */
|
30 | function fail(exception, success) {
|
31 | if (exception) {
|
32 | stderr.write((exception.stack || exception) + '\n');
|
33 | }
|
34 |
|
35 | if (exception || !success) {
|
36 | exitStatus = 1;
|
37 | }
|
38 | }
|
39 |
|
40 | /*
|
41 | * Set-up.
|
42 | */
|
43 |
|
44 | var position = argv.indexOf('--');
|
45 |
|
46 | if (position !== -1) {
|
47 | argv = argv.slice(0, position);
|
48 | }
|
49 |
|
50 | /*
|
51 | * Process.
|
52 | */
|
53 |
|
54 | cli(argv, fail);
|
55 |
|
56 | /*
|
57 | * Exit.
|
58 | */
|
59 |
|
60 | process.on('exit', function () {
|
61 | /* eslint-disable no-process-exit */
|
62 | process.exit(exitStatus);
|
63 | /* eslint-enable no-process-exit */
|
64 | });
|