<commit_before>#!/usr/bin/env node

import execPromise from 'exec-promise'

import commands from './commands'

function runCommand(commands, [command, ...args]) {
  if (command === undefined || command === '-h' || command === '--help') {
    command = 'help'
  }

  const fn = commands[command]

  if (fn === undefined) {
    if (command === 'help') {
      return `Usage:

${Object.keys(commands)
  .filter(command => command !== 'help')
  .map(command => `    ${this.command} ${command}`)
  .join('\n\n')}`
    }

    throw `invalid command ${command}` // eslint-disable-line no-throw-literal
  }

  return fn.call(
    {
      __proto__: this,
      command: `${this.command} ${command}`,
    },
    args
  )
}

execPromise(
  runCommand.bind(
    {
      command: 'vhd-cli',
      runCommand,<commit_msg>feat(vhd-cli): display version in usage<commit_after>#!/usr/bin/env node

import execPromise from 'exec-promise'

import pkg from '../package.json'

import commands from './commands'

function runCommand(commands, [command, ...args]) {
  if (command === undefined || command === '-h' || command === '--help') {
    command = 'help'
  }

  const fn = commands[command]

  if (fn === undefined) {
    if (command === 'help') {
      return `Usage:

${Object.keys(commands)
  .filter(command => command !== 'help')
  .map(command => `    ${this.command} ${command}`)
  .join('\n\n')}

vhd-cli ${pkg.version}`
    }

    throw `invalid command ${command}` // eslint-disable-line no-throw-literal
  }

  return fn.call(
    {
      __proto__: this,
      command: `${this.command} ${command}`,
    },
    args
  )
}

execPromise(
  runCommand.bind(
    {
      command: 'vhd-cli',
      runCommand,
{'fraction_non_alphanumeric': 0.18753674309229865, 'fraction_numerical': 0.0, 'mean_word_length': 2.8506787330316743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1336768', 'n_tokens_mistral': 571, 'n_tokens_neox': 567, 'n_words': 131}