Code coverage report for lib/cli.js

Statements: 100% (18 / 18)      Branches: 100% (2 / 2)      Functions: 100% (7 / 7)      Lines: 100% (18 / 18)      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 54 55 56 57 58 59 60 61 62 63 64 651       1 1     1 210 13       13 13 26 13   13                   1       15                                 15           15 210     15     1  
var _ = require('lodash'),
  cli = require('bagofcli'),
  Couchpenter = require('./couchpenter');
 
function _init() {
  new Couchpenter().init(cli.exit);
}
 
function _task(fn) {
  return function (args) {
    var couchpenter = new Couchpenter(
      args.parent.url,
      { setupFile: args.parent.setupFile, dir: args.parent.dir, interval: args.parent.interval }
    );
    couchpenter[fn](cli.exitCb(null, function (results) {
      results.forEach(function (result) {
        if (result.error) {
          console.error('%s - %s', result.id, result.message);
        } else {
          console.log('%s - %s', result.id, result.message);
        }
      });
    }));
  };
}
 
/**
 * Execute Couchpenter CLI.
 */
function exec() {
 
  // NOTE: pardon this cli target to Couchpenter methods mapping,
  // needed to preserve backward compatibility w/ v0.1.x
  const FUNCTIONS = {
    setup: 'setUp',
    'setup-db': 'setUpDatabases',
    'setup-doc': 'setUpDocuments',
    'setup-doc-overwrite': 'setUpDocumentsOverwrite',
    teardown: 'tearDown',
    'teardown-db': 'tearDownDatabases',
    'teardown-doc': 'tearDownDocuments',
    reset: 'reset',
    'reset-db': 'resetDatabases',
    'reset-doc': 'resetDocuments',
    clean: 'clean',
    'clean-db': 'cleanDatabases',
    'warm-view': 'warmViews',
    'live-deploy-view': 'liveDeployView'
  };
 
  var actions = {
    commands: {
      init: { action: _init }
    }
  };
 
  _.keys(FUNCTIONS).forEach(function (task) {
    actions.commands[task] = { action: _task(FUNCTIONS[task]) };
  });
 
  cli.command(__dirname, actions);
}
 
exports.exec = exec;