#!/usr/bin/env node

// Generated by CoffeeScript 2.5.1
(function() {
  var util, whois, yargs;

  yargs = require('yargs');

  whois = require('./index');

  util = require('util');

  yargs.usage('$0 [options] address').default('s', null).alias('s', 'server').describe('s', 'whois server').default('f', 0).alias('f', 'follow').describe('f', 'number of times to follow redirects').default('p', null).alias('p', 'proxy').describe('p', 'SOCKS proxy').boolean('v').default('v', false).alias('v', 'verbose').describe('v', 'show verbose results').default('b', null).alias('b', 'bind').describe('b', 'bind to a local IP address').boolean('h').default('h', false).alias('h', 'help').describe('h', 'display this help message');

  if (yargs.argv.h) {
    yargs.showHelp();
    process.exit(0);
  }

  if (yargs.argv._[0] == null) {
    yargs.showHelp();
    process.exit(1);
  }

  whois.lookup(yargs.argv._[0], {
    server: yargs.argv.server,
    follow: yargs.argv.follow,
    proxy: yargs.argv.proxy,
    verbose: yargs.argv.verbose,
    bind: yargs.argv.bind
  }, (err, data) => {
    var i, len, part, results;
    if (err != null) {
      console.log(err);
      process.exit(1);
    }
    if (util.isArray(data)) {
      results = [];
      for (i = 0, len = data.length; i < len; i++) {
        part = data[i];
        if ('object' === typeof part.server) {
          console.log(part.server.host);
        } else {
          console.log(part.server);
        }
        console.log(part.data);
        results.push(console.log);
      }
      return results;
    } else {
      return console.log(data);
    }
  });

}).call(this);
