#!/usr/bin/env node

var async = require('async');

var proxy = require('../lib/proxy');
var logger = require('../lib/logger');
var browsers = require('../lib/browsers');
var browserListenerProxy = require('../lib/proxy/browserListenerProxy');

require('whereis')('java', function searched(err) {
  // yep, we need Java for Selenium & the proxy
  if (err) {
    console.error(
      'Could not find Java, make sure it is installed in your $PATH');
  } else {
    var Browsertime = require('../lib/browsertime'),
      cli = require('../lib/cli'),
      argv = require('minimist')(process.argv.slice(2), {
        alias: {
          'u': 'url',
          'b': 'browser',
          'n': 'runs',
          'w': 'size',
          'f': 'filename',
          'V': 'version'
        }
      });

    cli.verifyInput(argv);

    logger.addLog(null, argv);

    var p = proxy.createProxy(argv);

    async.series([
          function (cb) {
            p.launchProcess(cb);
          },
          function (cb) {
            browsers.setProxy(p);

            var bt = new Browsertime(browsers);

            browserListenerProxy.setup(bt, p, argv);

            bt.fetch(argv, cb);
          }
        ],
        function (err) {
          p.stopProcess(function() {});

          process.exit(err ? 1 : 0);
        });
  }
});

@@ -1211,24 +1211,105 @@
 ion (err) %7B%0A
+          if (err) %7B%0A            logger.getLog().error(err.message);%0A          %7D%0A
           p.

Print errors before exiting.