Code coverage report for istanbul/lib/command/help.js

Statements: 100% (42 / 42)      Branches: 100% (4 / 4)      Functions: 100% (6 / 6)      Lines: 100% (42 / 42)      Ignored: none     

All files » istanbul/lib/command/ » help.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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99          89               89   1 1 1         1     1         1     1 1 1       1     1     89 7     89 89   89   5         4 4 4   4 4 24 24 24   4 4 4     9 9 1   8 1   7 7 5   2 2       9         89      
/*
 Copyright (c) 2012, Yahoo! Inc.  All rights reserved.
 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */
 
var Command = require('./index.js'),
    util = require('util'),
    formatOption = require('../util/help-formatter').formatOption,
    VERSION = require('../../index').VERSION,
    configuration = require('../config'),
    yaml = require('js-yaml'),
    formatPara = require('../util/help-formatter').formatPara;
 
function showConfigHelp(toolName) {
 
    console.error('\nConfiguring ' + toolName);
    console.error('====================');
    console.error('\n' +
        formatPara(toolName + ' can be configured globally using a .istanbul.yml YAML file ' +
            'at the root of your source tree. Every command also accepts a --config=<config-file> argument to ' +
            'customize its location per command. The alternate config file can be in YAML, JSON or node.js ' +
            '(exporting the config object).'));
    console.error('\n' +
        formatPara('The config file currently has three sections for instrumentation, reporting and hooks. ' +
            'Note that certain commands (like `cover`) use information from multiple sections.'));
    console.error('\n' +
        formatPara('Keys in the config file usually correspond to command line parameters with the same name. ' +
            'The verbose option for every command shows you the exact configuration used. See the api ' +
            'docs for an explanation of each key.'));
 
    console.error('\n' +
        formatPara('You only need to specify the keys that you want to override. Your overrides will be merged ' +
            'with the default config.'));
    console.error('\nThe default configuration is as follows:\n');
    console.error(yaml.safeDump(configuration.defaultConfig(), { indent: 4, flowLevel: 3 }));
    console.error('\n' +
        formatPara('The `watermarks` section does not have a command line equivalent. It allows you to set up ' +
            'low and high watermark percentages for reporting. These are honored by all reporters that colorize ' +
            'their output based on low/ medium/ high coverage.'));
    console.error('\n' +
        formatPara('The `reportConfig` section allows you to configure each report format independently ' +
            'and has no command-line equivalent either.'));
    console.error('');
}
 
function HelpCommand() {
    Command.call(this);
}
 
HelpCommand.TYPE = 'help';
util.inherits(HelpCommand, Command);
 
Command.mix(HelpCommand, {
    synopsis: function () {
        return "shows help";
    },
 
    usage: function () {
 
        console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' config | <command>\n');
        console.error('`config` provides help with istanbul configuration\n');
        console.error('Available commands are:\n');
 
        var commandObj;
        Command.getCommandList().forEach(function (cmd) {
            commandObj = Command.create(cmd);
            console.error(formatOption(cmd, commandObj.synopsis()));
            console.error("\n");
        });
        console.error("Command names can be abbreviated as long as the abbreviation is unambiguous");
        console.error(this.toolName() + ' version:' + VERSION);
        console.error("\n");
    },
    run: function (args, callback) {
        var command;
        if (args.length === 0) {
            this.usage();
        } else {
            if (args[0] === 'config') {
                showConfigHelp(this.toolName());
            } else {
                try {
                    command = Command.create(args[0]);
                    command.usage('istanbul', Command.resolveCommandName(args[0]));
                } catch (ex) {
                    console.error('Invalid command: ' + args[0]);
                    this.usage();
                }
            }
        }
        return callback();
    }
});
 
 
module.exports = HelpCommand;