1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const debug = require('debug')('mocha:cli:cli');
|
15 | const symbols = require('log-symbols');
|
16 | const yargs = require('yargs/yargs');
|
17 | const path = require('path');
|
18 | const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
|
19 | const commands = require('./commands');
|
20 | const ansi = require('ansi-colors');
|
21 | const {repository, homepage, version, gitter} = require('../../package.json');
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | exports.main = (argv = process.argv.slice(2)) => {
|
31 | debug('entered main with raw args', argv);
|
32 |
|
33 | module.paths.push(process.cwd(), path.resolve('node_modules'));
|
34 |
|
35 | Error.stackTraceLimit = Infinity;
|
36 |
|
37 | var args = loadOptions(argv);
|
38 |
|
39 | yargs()
|
40 | .scriptName('mocha')
|
41 | .command(commands.run)
|
42 | .command(commands.init)
|
43 | .updateStrings({
|
44 | 'Positionals:': 'Positional Arguments',
|
45 | 'Options:': 'Other Options',
|
46 | 'Commands:': 'Commands'
|
47 | })
|
48 | .fail((msg, err, yargs) => {
|
49 | debug(err);
|
50 | yargs.showHelp();
|
51 | console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
52 | process.exit(1);
|
53 | })
|
54 | .help('help', 'Show usage information & exit')
|
55 | .alias('help', 'h')
|
56 | .version('version', 'Show version number & exit', version)
|
57 | .alias('version', 'V')
|
58 | .wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
|
59 | .epilog(
|
60 | `Mocha Resources
|
61 | Chat: ${ansi.magenta(gitter)}
|
62 | GitHub: ${ansi.blue(repository.url)}
|
63 | Docs: ${ansi.yellow(homepage)}
|
64 | `
|
65 | )
|
66 | .parserConfiguration(YARGS_PARSER_CONFIG)
|
67 | .config(args)
|
68 | .parse(args._);
|
69 | };
|
70 |
|
71 |
|
72 | if (require.main === module) {
|
73 | exports.main();
|
74 | }
|