<commit_before>var fs = require('fs'),
    parseCmd = require('./util/parse_cmd'),
    path = require('path'),
    debug = require('debug')('mj');

function wrapCommand(cmd) {
  return function(args, done) {
    // parse cmd line arguments, use args string if provided
    var argv = parseCmd(cmd, args);

    // defaults
    argv['<directory>'] = path.resolve(argv['<directory>']) || process.cwd();
    
    debug('running command `%s`', cmd);
    require('./commands/' + cmd)(argv, function(err, res) {
      done(err, res);
    });
  };
}

var commands = {};
fs.readdirSync(__dirname + '/commands').forEach(function(file) {
  var name = file.replace('.js', '');
  commands[name] = wrapCommand(name);
});
debug('Loaded commands %s', Object.keys(commands));

module.exports = commands;<commit_msg>need to check argv['<directory>'] before passing to path.resolve.<commit_after>var fs = require('fs'),
    parseCmd = require('./util/parse_cmd'),
    path = require('path'),
    debug = require('debug')('mj');

function wrapCommand(cmd) {
  return function(args, done) {
    // parse cmd line arguments, use args string if provided
    var argv = parseCmd(cmd, args);    

    // defaults
    argv['<directory>'] = argv['<directory>'] ? path.resolve(argv['<directory>']) : process.cwd();
    
    debug('running command `%s`', cmd);
    require('./commands/' + cmd)(argv, function(err, res) {
      done(err, res);
    });
  };
}

var commands = {};
fs.readdirSync(__dirname + '/commands').forEach(function(file) {
  var name = file.replace('.js', '');
  commands[name] = wrapCommand(name);
});
debug('Loaded commands %s', Object.keys(commands));

module.exports = commands;
{'fraction_non_alphanumeric': 0.1936640765092648, 'fraction_numerical': 0.0, 'mean_word_length': 3.9235294117647057, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3118708', 'n_tokens_mistral': 513, 'n_tokens_neox': 507, 'n_words': 119}