<commit_before>import chalk from 'chalk';
import debugModule from 'debug';
import program from 'commander';
import {defaultOutputHelp, errorAndExit, noCommandAndExit} from './utils';
import Jungle from '../';

const debug = debugModule('jungle:cli');


const STATUS_STYLES = {
  stopped: chalk.red,
  running: chalk.green,
  '*': chalk.gray.dim
};


function coloredStatus(stateName) {
  const statusStyle = STATUS_STYLES[stateName] || STATUS_STYLES['*'];
  return statusStyle(stateName);
}


program.option('-r, --region <name>', 'Region name');
program.action(noCommandAndExit('jungle ec2'));

program.command('ls [name]')
.description('List EC2 Instances')
.action((name, options) => {
  const jungle = new Jungle(options.parent.region);
  jungle.ec2.getInstances(name).then(instances => {
    instances.forEach(i => {
      const nameTag = i.Tags.filter(t => t.Key === 'Name').shift();
      const cols = [
        nameTag ? nameTag.Value : null,
        coloredStatus(i.State.Name),
        i.InstanceId,
        i.PrivateIpAddress || null,
        i.PublicIpAddress || null
      ];
      console.log(cols.join('\t'));
    });
  }).catch(errorAndExit);
});
<commit_msg>refactor(commands): Use getTagValue<commit_after>import chalk from 'chalk';
import debugModule from 'debug';
import program from 'commander';
import {defaultOutputHelp, errorAndExit, noCommandAndExit} from './utils';
import Jungle from '../';
import {getTagValue} from '../utils';

const debug = debugModule('jungle:cli');


const STATUS_STYLES = {
  stopped: chalk.red,
  running: chalk.green,
  '*': chalk.gray.dim
};


function coloredStatus(stateName) {
  const statusStyle = STATUS_STYLES[stateName] || STATUS_STYLES['*'];
  return statusStyle(stateName);
}


program.option('-r, --region <name>', 'Region name');
program.action(noCommandAndExit('jungle ec2'));

program.command('ls [name]')
.description('List EC2 Instances')
.action((name, options) => {
  const jungle = new Jungle(options.parent.region);
  jungle.ec2.getInstances(name).then(instances => {
    instances.forEach(i => {
      const cols = [
        getTagValue(i.Tags, 'Name') || null,
        coloredStatus(i.State.Name),
        i.InstanceId,
        i.PrivateIpAddress || null,
        i.PublicIpAddress || null
      ];
      console.log(cols.join('\t'));
    });
  }).catch(errorAndExit);
});

{'fraction_non_alphanumeric': 0.1631870472944184, 'fraction_numerical': 0.0025564550489987218, 'mean_word_length': 4.00639658848614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1176961', 'n_tokens_mistral': 765, 'n_tokens_neox': 756, 'n_words': 155}