<commit_before>var fs = require('fs');
var path = require('path');
var util = require('util');

var optionator = require('optionator');


var manifest = {
	name: '<module>',
	version: ''
};
var argParser = optionator({
	prepend: 'Usage: ' + manifest.name + ' [command] [options]',
	options: [
		{
			option: 'help',
			alias: 'h',
			type: 'Boolean',
			description: 'Displays help'
		},
		{
			option: 'version',
			alias: 'v',
			type: 'Boolean',
			description: 'Displays version'
		}
	]
});


function init(mnfst) {
	manifest = mnfst;

	return module.exports;
}


function exec(argv) {
	var args, cmd, command, resolved, result;

	argv = argv.slice();

	if (argv[2] && argv[2].charAt(0) !== '-') {
		cmd = argv.splice(2, 1)[0];
	}

	if (!cmd) {
		args = argParser.parse(argv);

		if (args.help) {
			showHelp();
			process.exit(0);
		}

		if (args.version) {
			util.puts(manifest.name + ' ' + manifest.version);
			process.exit(0);
		}
	}

	resolved = path.resolve(path.join(__dirname, 'commands', cmd + '.js'));
	command = require(resolved);
	result = command.main(process.argv);

	if (typeof result === 'string') {
		util.puts(result);
	}

	if (command.persist !== true) {
		process.exit(0);
	}
}


function help() {
	var i, dir, dirname, filename, files, name;

	dirname = path.resolve(path.join(__dirname, 'commands'));
	dir = fs.readdirSync(dirname);
	files = [];

	for (i = 0; i < dir.length; i++) {
		filename = path.join(dirname, dir[i]);

		if (!fs.statSync(filename).isDirectory()) {
			name = path.basename(filename, path.extname(filename));
			files.push(name);
		}
	}

	util.puts(argParser.generateHelp());
	util.puts('\nAvailable commands:');

	for (i = 0; i < files.length; i++) {
		util.puts('  ' + files[i]);
	}
}


module.exports = {
	exec: exec,
	help: help,
	init: init
};
<commit_msg>Need to load in settings as part of the module definition.<commit_after>var fs = require('fs');
var path = require('path');
var util = require('util');

var optionator = require('optionator');


var argParser, manifest, root;


function exec(argv) {
	var args, cmd, command, resolved, result;

	argv = argv.slice();

	if (argv[2] && argv[2].charAt(0) !== '-') {
		cmd = argv.splice(2, 1)[0];
	}

	if (!cmd) {
		args = argParser.parse(argv);

		if (args.help) {
			showHelp();
			process.exit(0);
		}

		if (args.version) {
			util.puts(manifest.name + ' ' + manifest.version);
			process.exit(0);
		}
	}

	try {
		resolved = path.resolve(path.join(root, 'commands', cmd + '.js'));
	}
	catch(ex) {
		util.puts('Command directory not found.');
		process.exit(0);
	}

	try {
		command = require(resolved);
	}
	catch(ex) {
		util.puts('Command `' + cmd + '` not found.');
		process.exit(0);
	}

	result = command.main(process.argv);

	if (typeof result === 'string') {
		util.puts(result);
	}

	if (command.persist !== true) {
		process.exit(0);
	}
}


function help() {
	var i, dir, dirname, filename, files, name;

	try {
		dirname = path.resolve(path.join(root, 'commands'));
	}
	catch(ex) {
		util.puts('Command directory not found.');
		process.exit(0);
	}

	dir = fs.readdirSync(dirname);
	files = [];

	for (i = 0; i < dir.length; i++) {
		filename = path.join(dirname, dir[i]);

		if (!fs.statSync(filename).isDirectory()) {
			name = path.basename(filename, path.extname(filename));
			files.push(name);
		}
	}

	util.puts(argParser.generateHelp());
	util.puts('\nAvailable commands:');

	for (i = 0; i < files.length; i++) {
		util.puts('  ' + files[i]);
	}
}


module.exports = function init(mnfst, rt) {
	manifest = mnfst;
	root = rt;
	argParser = optionator({
		prepend: 'Usage: ' + manifest.name + ' [command] [options]',
		options: [
			{
				option: 'help',
				alias: 'h',
				type: 'Boolean',
				description: 'Displays help'
			},
			{
				option: 'version',
				alias: 'v',
				type: 'Boolean',
				description: 'Displays version'
			}
		]
	});

	return {
		exec: exec,
		help: help,
		init: init
	};
};

{'fraction_non_alphanumeric': 0.19440203562340966, 'fraction_numerical': 0.006361323155216285, 'mean_word_length': 3.4268018018018016, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, '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': '1948019', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1459, 'n_words': 321}