Code coverage report for lib/cli.js

Statements: 100% (22 / 22)      Branches: 100% (10 / 10)      Functions: 100% (8 / 8)      Lines: 100% (22 / 22)      Ignored: none     

All files » lib/ » cli.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 541         1 1     1   1 3 3 1 1     2         1 3 5   3     3 3 3 3             1   5             5     1  
var _ = require('lodash'),
  bag = require('bagofcli'),
  Health = require('./health'),
  util = require('util');
 
function _init() {
  new Health().init(bag.exit);
}
 
function _check(args) {
 
  function log(result) {
    var formatted = require('./formatters/' + (args.formatter || 'cli')).format(result);
    if (Array.isArray(formatted)) {
      formatted.forEach(function (line) {
        console.log(line);
      });
    } else {
      console.log(formatted);
    }
  }
 
  // determine exit code using the number of non-success status
  function exit(result) {
    var numNonSuccess = _.countBy(result, function (item) {
      return (item.status === 'success') ? 'success' : 'non-success';
    })['non-success'] || 0;
    process.exit(numNonSuccess);
  }
 
  var setup = JSON.parse(bag.lookupFile(args.setupFile || 'health.json'));
  new Health({ setup: setup }).check(bag.exitCb(null, function (result) {
    log(result);
    exit(result);
  }));
}
 
/**
 * Execute Health CLI.
 */
function exec() {
 
  var actions = {
    commands: {
      init: { action: _init },
      check: { action: _check }
    }
  };
 
  bag.command(__dirname, actions);
}
 
exports.exec = exec;