1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var Command = require('./index.js'),
|
7 | util = require('util'),
|
8 | formatOption = require('../util/help-formatter').formatOption,
|
9 | VERSION = require('../../index').VERSION,
|
10 | configuration = require('../config'),
|
11 | yaml = require('js-yaml'),
|
12 | formatPara = require('../util/help-formatter').formatPara;
|
13 |
|
14 | function showConfigHelp(toolName) {
|
15 |
|
16 | console.error('\nConfiguring ' + toolName);
|
17 | console.error('====================');
|
18 | console.error('\n' +
|
19 | formatPara(toolName + ' can be configured globally using a .istanbul.yml YAML file ' +
|
20 | 'at the root of your source tree. Every command also accepts a --config=<config-file> argument to ' +
|
21 | 'customize its location per command. The alternate config file can be in YAML, JSON or node.js ' +
|
22 | '(exporting the config object).'));
|
23 | console.error('\n' +
|
24 | formatPara('The config file currently has four sections for instrumentation, reporting, hooks, ' +
|
25 | 'and checking. Note that certain commands (like `cover`) use information from multiple sections.'));
|
26 | console.error('\n' +
|
27 | formatPara('Keys in the config file usually correspond to command line parameters with the same name. ' +
|
28 | 'The verbose option for every command shows you the exact configuration used. See the api ' +
|
29 | 'docs for an explanation of each key.'));
|
30 |
|
31 | console.error('\n' +
|
32 | formatPara('You only need to specify the keys that you want to override. Your overrides will be merged ' +
|
33 | 'with the default config.'));
|
34 | console.error('\nThe default configuration is as follows:\n');
|
35 | console.error(yaml.safeDump(configuration.defaultConfig(), { indent: 4, flowLevel: 3 }));
|
36 | console.error('\n' +
|
37 | formatPara('The `watermarks` section does not have a command line equivalent. It allows you to set up ' +
|
38 | 'low and high watermark percentages for reporting. These are honored by all reporters that colorize ' +
|
39 | 'their output based on low/ medium/ high coverage.'));
|
40 | console.error('\n' +
|
41 | formatPara('The `reportConfig` section allows you to configure each report format independently ' +
|
42 | 'and has no command-line equivalent either.'));
|
43 | console.error('\n' +
|
44 | formatPara('The `check` section configures minimum threshold enforcement for coverage results. ' +
|
45 | '`global` applies to all files together and `each` on a per-file basis. A list of files can ' +
|
46 | 'be excluded from enforcement relative to root via the `exclude` property.'));
|
47 | console.error('');
|
48 | }
|
49 |
|
50 | function HelpCommand() {
|
51 | Command.call(this);
|
52 | }
|
53 |
|
54 | HelpCommand.TYPE = 'help';
|
55 | util.inherits(HelpCommand, Command);
|
56 |
|
57 | Command.mix(HelpCommand, {
|
58 | synopsis: function () {
|
59 | return "shows help";
|
60 | },
|
61 |
|
62 | usage: function () {
|
63 |
|
64 | console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' config | <command>\n');
|
65 | console.error('`config` provides help with istanbul configuration\n');
|
66 | console.error('Available commands are:\n');
|
67 |
|
68 | var commandObj;
|
69 | Command.getCommandList().forEach(function (cmd) {
|
70 | commandObj = Command.create(cmd);
|
71 | console.error(formatOption(cmd, commandObj.synopsis()));
|
72 | console.error("\n");
|
73 | });
|
74 | console.error("Command names can be abbreviated as long as the abbreviation is unambiguous");
|
75 | console.error(this.toolName() + ' version:' + VERSION);
|
76 | console.error("\n");
|
77 | },
|
78 | run: function (args, callback) {
|
79 | var command;
|
80 | if (args.length === 0) {
|
81 | this.usage();
|
82 | } else {
|
83 | if (args[0] === 'config') {
|
84 | showConfigHelp(this.toolName());
|
85 | } else {
|
86 | try {
|
87 | command = Command.create(args[0]);
|
88 | command.usage('istanbul', Command.resolveCommandName(args[0]));
|
89 | } catch (ex) {
|
90 | console.error('Invalid command: ' + args[0]);
|
91 | this.usage();
|
92 | }
|
93 | }
|
94 | }
|
95 | return callback();
|
96 | }
|
97 | });
|
98 |
|
99 |
|
100 | module.exports = HelpCommand;
|
101 |
|
102 |
|