
var _     = require('lodash')
var chalk = require('chalk')

var helpers = {

  // Pick off the attributes from only the current layer of the object.
  skim: function(data) {
    return _.map(data, function(obj) {
      return _.pick(obj, _.keys(obj));
    });
  },

  // Check if the first argument is an array, otherwise
  // uses all arguments as an array.
  normalizeArr: function() {
    var args = new Array(arguments.length);
    for (var i = 0; i < args.length; i++) {
      args[i] = arguments[i];
    }
    if (Array.isArray(args[0])) {
      return args[0];
    }
    return args;
  },

  error: function(msg) {
    console.log(chalk.red('Knex:Error ' + msg))
  },

  // Used to signify deprecated functionality.
  deprecate: function(method, alternate) {
    helpers.warn(method + ' is deprecated, please use ' + alternate);
  },

  // Used to warn about incorrect use, without error'ing
  warn: function(msg) {
    console.log(chalk.yellow("Knex:warning - " + msg))
  },

  exit: function(msg) {
    console.log(chalk.red(msg))
    process.exit()
  }

};

module.exports = helpers;

var _     = require('lodash')
var chalk = require('chalk')

var helpers = {

  // Pick off the attributes from only the current layer of the object.
  skim: function(data) {
    return _.map(data, function(obj) {
      return _.pick(obj, _.keys(obj));
    });
  },

  // Check if the first argument is an array, otherwise
  // uses all arguments as an array.
  normalizeArr: function() {
    var args = new Array(arguments.length);
    for (var i = 0; i < args.length; i++) {
      args[i] = arguments[i];
    }
    if (Array.isArray(args[0])) {
      return args[0];
    }
    return args;
  },

  error: function(msg) {
    console.log(chalk.red('Knex:Error ' + msg))
  },

  // Used to signify deprecated functionality.
  deprecate: function(method, alternate) {
    helpers.warn(method + ' is deprecated, please use ' + alternate);
  },

  // Used to warn about incorrect use, without error'ing
  warn: function(msg) {
    console.log(chalk.yellow("Knex:warning - " + msg))
  },

  exit: function(msg) {
    console.log(chalk.red(msg))
    process.exit(1)
  }

};

module.exports = helpers;
Fix calling process.exit with "ok" exit code
Fix calling process.exit with "ok" exit code

We have a helper to log an error message to the console and exit the process. It looks like the only place we use this helper is when we try and fail to [initialize the driver](https://github.com/tgriesser/knex/blob/5a94bc9b178d399e23a80ff396a0fc7ec01ecc9b/src/client.js#L159).

Unfortunately, when we call `process.exit()` without an exit code, it [exits with a `0` exit code](https://nodejs.org/api/process.html#process_process_exit_code) -- which means success.

This is especially a problem when running tests in a CI environment, as it results in a false positive: tests not only do not pass, but they probably didn't even run.
