2 Copyright (c) 2012, Yahoo! Inc. All rights reserved.
3 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
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;
14 function showConfigHelp(toolName) {
16 console.error('\nConfiguring ' + toolName);
17 console.error('====================');
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).'));
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.'));
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.'));
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 }));
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.'));
41 formatPara('The `reportConfig` section allows you to configure each report format independently ' +
42 'and has no command-line equivalent either.'));
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.'));
50 function HelpCommand() {
54 HelpCommand.TYPE = 'help';
55 util.inherits(HelpCommand, Command);
57 Command.mix(HelpCommand, {
58 synopsis: function () {
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');
69 Command.getCommandList().forEach(function (cmd) {
70 commandObj = Command.create(cmd);
71 console.error(formatOption(cmd, commandObj.synopsis()));
74 console.error("Command names can be abbreviated as long as the abbreviation is unambiguous");
75 console.error(this.toolName() + ' version:' + VERSION);
78 run: function (args, callback) {
80 if (args.length === 0) {
83 if (args[0] === 'config') {
84 showConfigHelp(this.toolName());
87 command = Command.create(args[0]);
88 command.usage('istanbul', Command.resolveCommandName(args[0]));
90 console.error('Invalid command: ' + args[0]);
100 module.exports = HelpCommand;