#! /usr/bin/env node

/**
 * Module dependencies.
 */

import { get, keys, omit, pickBy, values } from 'lodash';
import { readFile } from 'fs';
import { version } from '../../package.json';
import Promise from 'bluebird';
import inquirer from 'inquirer';
import prettyjson from 'prettyjson';
import updateLabels from '../';
import yargs from 'yargs';

/**
 * Promisify fs readFile method.
 */

const readFileAsync = Promise.promisify(readFile);

/**
 * Program options.
 */

const args = yargs
  .usage('Usage: $0 [options]')
  .env('GITHUB_LABELS')
  .option('owner', { demand: false, describe: 'Repository owner', type: 'string' })
  .option('repo', { demand: false, describe: 'Repository name', type: 'string' })
  .option('token', { demand: true, describe: 'GitHub authentication token', type: 'string' })
  .option('configFile', { demand: false, describe: 'Configuration file', type: 'string' })
  .help('h')
  .alias('h', 'help')
  .version('version', 'Version', version)
  .alias('V', 'version')
  .example('$0 --owner foo --repo bar --token foobar --configFile ./path/somefile')
  .wrap(null)
  .argv;

/**
 * Program questions.
 */

const questions = {
  configFile: {
    message: 'What is the configuration file path?',
    name: 'configFile',
    validate: input => !!input
  },
  owner: {
    message: 'What is the owner name?',
    name: 'owner',
    validate: input => !!input
  },
  repo: {
    message: 'What is the repository name?',
    name: 'repo',
    validate: input => !!input
  }
};

/**
 * Program.
 */

(async function() {
  const answers = await inquirer.prompt(values(omit(questions, keys(pickBy(args)))));
  const options = { ...args, ...answers };

  // Retrieve labels from file.
  const content = await readFileAsync(get(options, 'configFile'), 'utf8');
  const labels = JSON.parse(content);

  await updateLabels({ ...options, labels });

  return console.log(prettyjson.render(labels)); // eslint-disable-line no-console
})();

@@ -61,1902 +61,646 @@
 t %7B 
-get, keys, omit, pickBy, values %7D from 'lodash';%0Aimport %7B readFile %7D from 'fs';%0Aimport %7B version %7D from '../../package.json';%0Aimport Promise from 'bluebird';%0Aimport inquirer from 'inquirer';%0Aimport prettyjson from 'prettyjson';%0Aimport updateLabels from '../';%0Aimport yargs from 'yargs';%0A%0A/**%0A * Promisify fs readFile method.%0A */%0A%0Aconst readFileAsync = Promise.promisify(readFile);%0A%0A/**%0A * Program options.%0A */%0A%0Aconst args = yargs%0A  .usage('Usage: $0 %5Boptions%5D')%0A  .env('GITHUB_LABELS')%0A  .option('owner', %7B demand: false, describe: 'Repository owner', type: 'string' %7D)%0A  .option('repo', %7B demand: false, describe: 'Repository name', type: 'string' %7D)%0A  .option('token', %7B demand: true, describe: 'GitHub authentication token', type: 'string' %7D)%0A  .option('configFile', %7B demand: false, describe: 'Configuration file', type: 'string' %7D)%0A  .help('h')%0A  .alias('h', 'help')%0A  .version('version', 'Version', version)%0A  .alias('V', 'version')%0A  .example('$0 --owner foo --repo bar --token foobar --configFile ./path/somefile')%0A  .wrap(null)%0A  .argv;%0A%0A/**%0A * Program questions.%0A */%0A%0Aconst questions = %7B%0A  configFile: %7B%0A    message: 'What is the configuration file path?',%0A    name: 'configFile',%0A    validate: input =%3E !!input%0A  %7D,%0A  owner: %7B%0A    message: 'What is the owner name?',%0A    name: 'owner',%0A    validate: input =%3E !!input%0A  %7D,%0A  repo: %7B%0A    message: 'What is the repository name?',%0A    name: 'repo',%0A    validate: input =%3E !!input%0A  %7D%0A%7D;%0A%0A/**%0A * Program.%0A */%0A%0A(async function() %7B%0A  const answers = await inquirer.prompt(values(omit(questions, keys(pickBy(args)))));%0A  const options = %7B ...args, ...answers %7D;%0A%0A  // Retrieve labels from file.%0A  const content = await readFileAsync(get(options, 'configFile'), 'utf8');%0A  const labels = JSON.parse(content);%0A%0A  await updateLabels(%7B ...options, labels %7D);%0A%0A  return console.log(prettyjson.render(labels)); // eslint-disable-line no-console%0A%7D)()
+copyFromRepo, copyFromRepoConfig %7D from '../commands/copy-from-repo-command';%0Aimport %7B update, updateConfig %7D from '../commands/update-command';%0Aimport %7B version %7D from '../../package.json';%0Aimport yargs from 'yargs';%0A%0A/**%0A * Program options.%0A */%0A%0Ayargs // eslint-disable-line no-unused-expressions%0A  .usage('Usage: $0 %5Boptions%5D')%0A  .env('GITHUB_LABELS')%0A  .command(%5B'*', 'update'%5D, 'Update repository labels', updateConfig, update)%0A  .command('copy', 'Copy labels from repository', copyFromRepoConfig, copyFromRepo)%0A  .help('h')%0A  .alias('h', 'help')%0A  .version('version', 'Version', version)%0A  .alias('V', 'version')%0A  .wrap(null)%0A  .argv
 ;%0A

Update labels bin to use commands