<commit_before>#!/usr/bin/env node
'use strict';

const path = require('path');

/* Node v8.1.2 does not support ES2015-style modules without --harmony. */
const InputParser = require('../dist/InputParser.js').default;
const Dispatcher = require('../dist/Dispatcher.js').default;

let program = path.basename(process.argv[1], '.js');

if (program == 'index') {
  process.argv.shift();
  program = path.basename(process.argv[1], '.js');
}

const argv = process.argv.slice(2);
const parser = new InputParser();

parser.parse(argv).then((input) => {
  const results = Dispatcher.execute(program, input);

  if (results.error) {
    console.log(results.error);
  } else {
    /* TODO: May have to extract this out. */
    console.log(results.results.join('\n'));
  }
});<commit_msg>Add debug information to index<commit_after>#!/usr/bin/env node
'use strict';

const debug = require('debug')('Index');
const verbose = require('debug')('Index:Verbose');

const path = require('path');

/* Node v8.1.2 does not support ES2015-style modules without --harmony. */
const InputParser = require('../dist/InputParser.js').default;
const Dispatcher = require('../dist/Dispatcher.js').default;

let program = path.basename(process.argv[1], '.js');

debug('Starting up');

if (program == 'index') {
  process.argv.shift();
  program = path.basename(process.argv[1], '.js');
}

debug(`Decoded program ${program}`)

const argv = process.argv.slice(2);
const parser = new InputParser();

debug('Parsing arguments...')

parser.parse(argv).then((input) => {
  debug('Parsing arguments... done.')
  debug(`Dispatching ${input.length} input argument(s) to ${program}.`);

  verbose(`Got input %O from argv %O`, input, argv);
  const results = Dispatcher.execute(program, input);

  if (results.error) {
    console.log(results.error);
    debug(`Error: %O`, results.error);
  } else {
    debug(`Returning ${results.results.length} result(s) via stdout.`);
    verbose(`%O`, results.results);
    /* TODO: May have to extract this out. */
    console.log(results.results.join('\n'));
  }
});
{'fraction_non_alphanumeric': 0.1904301594973417, 'fraction_numerical': 0.009666505558240696, 'mean_word_length': 4.253807106598985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6145868', 'n_tokens_mistral': 674, 'n_tokens_neox': 656, 'n_words': 158}