#!/usr/bin/env node

var chalk = require('chalk');
var leftpad = require('left-pad');
var minimist = require('minimist');
var spinner = require('ora')('Loading...');

var movieman = require('./dist');
var version = require('./package.json').version;

var defaults = {
  alias: {
    h: 'help',
    v: 'version'
  },
  boolean: ['help', 'version']
};

var help = `
  Usage
    $ movieman <title> [--help] [--version]

  Options
    -h --help      Display this help dialog.
    -v --version   Display the current version.

  Example
    $ movieman batman
`;

var options = minimist(process.argv.slice(2), defaults);

if (options.help) {
  console.log(help);
  process.exit(0);
} else if (options.version) {
  console.log('v' + version);
  process.exit(0);
}

var title = options._.join(' ');
if (!title) {
  console.error('Expected movie title. Run `movieman -h` for help.')
  process.exit(1);
}

spinner.start();

movieman.getMovie().by.title(title, function(err, res) {
  if (err) throw err;

  spinner.stop();

  Object.keys(res).forEach(function(key) {
    console.log(key + chalk.yellow(leftpad('-›  ', 18 - key.length)) + res[key]);
  });
});

@@ -303,16 +303,30 @@
 version'
+,%0A    i: 'id',
 %0A  %7D,%0A  
@@ -339,16 +339,21 @@
 n: %5B
+%0A    
 'help', 
 'ver
@@ -348,16 +348,21 @@
 'help', 
+%0A    
 'version
@@ -362,17 +362,53 @@
 version'
-%5D
+,%0A  %5D,%0A  default: %7B%0A    i: null,%0A  %7D,
 %0A%7D;%0A%0Avar
@@ -447,16 +447,33 @@
  %3Ctitle%3E
+ %5B--id %3Cimdb_id%3E%5D
  %5B--help
@@ -485,16 +485,17 @@
 version%5D
+ 
 %0A%0A  Opti
@@ -595,308 +595,639 @@
 on.%0A
-%0A  Example%0A    $ movieman batman%0A%60;%0A%0Avar options = minimist(process.argv.slice(2), defaults);%0A%0Aif (options.help) %7B%0A  console.log(help);%0A  process.exit(0);%0A%7D else if (options.version) %7B%0A  console.log('v' + version);%0A  process.exit(0);%0A%7D%0A%0Avar title = options._.join(' ');%0Aif (!title) %7B%0A  console.error(
+    -i --id        Use IMDb ID instead of movie title.%0A%0A  Example%0A    $ movieman the dark knight%0A    $ movieman --id tt0468569%0A%60;%0A%0Avar options = minimist(process.argv.slice(2), defaults);%0A%0Aif (options.help %7C%7C options.version) %7B%0A  console.log(options.help ? help : 'v' + version);%0A  process.exit(0);%0A%7D%0A%0Avar param, getMovie; %0A%0Aif (options.id) %7B%0A  param = options._.length %3E 0 ? options._%5B0%5D : options.id;%0A  getMovie = movieman.getMovie.by.id;%0A%7D else %7B%0A  param = options._.join(' ');%0A  getMovie = movieman.getMovie.by.title;%0A%7D%0A%0Aif (!param %7C%7C !param.length %7C%7C param.trim() === '') %7B%0A  console.error((options.id ? 'Expected IMDb ID.' : 
 'Exp
@@ -1244,16 +1244,22 @@
 e title.
+') + '
  Run %60mo
@@ -1266,17 +1266,21 @@
 vieman -
-h
+-help
 %60 for he
@@ -1284,16 +1284,17 @@
  help.')
+;
 %0A  proce
@@ -1330,42 +1330,22 @@
 );%0A%0A
-movieman.getMovie().by.title(title
+getMovie(param
 , fu

Add support for searching with IMDb movie ID