#!/usr/bin/env node
'use strict';

const meow = require('meow');
const chalk = require('chalk');
const pkg = require('./package.json');
const emojiSuggestions = require('./');

const flag = {
  error: msg => chalk.red(`🆘 : ${msg}`)
};

const cli = meow(`
  Usage:
    $ ${pkg.name} <word>

  Options:
    --help      Show information
    --version   Show current version

  Example:
    $ ${pkg.name} hello
`);

const args = cli.input.reduce((parsedArgs, arg) => {
  parsedArgs.word = arg;
  return parsedArgs;
}, {});

if (!Object.keys(args).length) {
  console.error(`
    ${flag.error(`Missing <word> argument.`)}
    ${flag.error(`Try \`${pkg.name} --help\` for more information.`)}
  `);
  process.exit(1);
}

if (!args.word) {
  console.error(`
    ${flag.error(`You need to specify a word`)}
  `);
  process.exit(1);
}

emojiSuggestions(args.word).forEach(suggestion => {
  console.log(`
    ${args.word} ${suggestion[args.word]}
  `);
});

@@ -820,16 +820,36 @@
 (1);%0A%7D%0A%0A
+const suggestions = 
 emojiSug
@@ -867,16 +867,51 @@
 gs.word)
+;%0A%0Aif (suggestions) %7B%0A  suggestions
 .forEach
@@ -927,16 +927,18 @@
 on =%3E %7B%0A
+  
   consol
@@ -949,16 +949,18 @@
 g(%60%0A    
+  
 $%7Bargs.w
@@ -993,14 +993,20 @@
 d%5D%7D%0A
+  
   %60);%0A
+  
 %7D);%0A
+%7D%0A

fix "TypeError" if there are no suggestions ✅