Code coverage report for src/arg-parser.js

Statements: 94.74% (36 / 38)      Branches: 92.86% (13 / 14)      Functions: 100% (5 / 5)      Lines: 94.74% (36 / 38)      Ignored: none     

All files » src/ » arg-parser.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  1 1 1   1 1   1 1 1       1         1           1 3 3     1 13 13 13 36       1   11 11 11 11 11 22 10 10   22 3 3 3     11       11 10 10   11      
'use strict';
var path = require('path');
var _ = require('lodash');
var logger = require('./log')('arg-parser');
 
var simpleDetail = 'simple-detail';
var formatterPath = 'formatters';
 
var defaultPath = './';
var formatKey = '-f';
var keys = {
  '-w': true,
  '--watch': true
};
var formats = { // still don't like this can cause too much duplication
  'simple': true,
  'simple-success': true,
  'simple-detail': true
};
var bin = {
  node: 'node',
  iojs: 'iojs',
  esw: 'esw'
};
 
var getPath = function(options){
  logger.debug('getPath: %s', options.format);
  return path.join(__dirname, formatterPath, options.format);
};
 
var contains = function(str, items){
  logger.debug(items);
  logger.debug('contains %s', str);
  return _.some(items, function(item){
    return str.indexOf(item) >= 0;
  });
};
 
module.exports = {
  parse: function (args, options) {
    var arr = [];
    var dirs = options._;
    var formatSpecified = false;
    logger.debug('Directories to check: %s', dirs);
    _.each(args, function(item){
      if (!keys[item] && !formats[item] && !bin[item] && !contains(item, [bin.esw, bin.iojs, bin.node])) {
        logger.debug('Pushing item: %s', item);
        arr.push(item);
      }
      if (formats[item]) {
        formatSpecified = true;
        logger.debug('Format specified');
        arr.push(getPath(options));
      }
    });
    Iif (options.format === simpleDetail && !formatSpecified) {
      arr.push(formatKey);
      arr.push(getPath(options));
    }
    if (!dirs.length) {
      arr.push(defaultPath);
      logger.debug('Setting default path: %s', defaultPath);
    }
    return arr;
  }
};