var mout = require('mout');
var nopt = require('nopt');
var renderers = require('../renderers');

function readOptions(options, argv) {
    var types;
    var noptOptions;
    var parsedOptions = {};
    var shorthands = {};

    if (Array.isArray(options)) {
        argv = options;
        options = {};
    } else {
        options = options || {};
    }

    types = mout.object.map(options, function (option) {
        return option.type;
    });
    mout.object.forOwn(options, function (option, name) {
        shorthands[option.shorthand] = '--' + name;
    });

    noptOptions = nopt(types, shorthands, argv);

    // Filter only the specified options because nopt parses every --
    options = mout.object.filter(noptOptions, function (value, key) {
        return !!options[key];
    });

    // Construct the final options, making every key camelCase
    mout.object.forOwn(options, function (value, key) {
        parsedOptions[mout.string.camelCase(key)] = value;
    });

    parsedOptions.argv = noptOptions.argv;

    return parsedOptions;
}

function getRenderer(command, config) {
    if (config.json) {
        return new renderers.Json(command);
    }

    return new renderers.Standard(command, config.color);
}

module.exports.readOptions = readOptions;
module.exports.getRenderer = getRenderer;

@@ -688,25 +688,47 @@
  --%0A    
-options =
+// and make them camel case%0A   
  mout.ob
@@ -733,21 +733,21 @@
 object.f
-ilter
+orOwn
 (noptOpt
@@ -788,17 +788,12 @@
     
-return !!
+if (
 opti
@@ -804,138 +804,16 @@
 key%5D
-;%0A    %7D);%0A%0A    // Construct the final options, making every key camelCase%0A    mout.object.forOwn(options, function (value, key
 ) %7B%0A
+    
     
@@ -867,16 +867,26 @@
  value;%0A
+        %7D%0A
     %7D);%0A

Simplify code.