<commit_before>var fs = require('fs');
var path = require('path');
var async = require('async');
var cliOptions = require('commander');

var packageJson = require('../package.json');
var componentHint = require('./component-hint.js');


/**
 * Function which re-formats commander option descriptions to have correct new lines and padding.
 * This makes the output a whole lot cleaner with long description strings, and takes terminal
 * window width into consideration.
 * 
 * @param {Array} options - options array from commander object
 * @param {Integer} width - maximum width for output, this should include padding size
 * @returns {undefined}
 */
function formatOptionStrings (options, width) {
	var totalWidth = (width < process.stdout.columns) ? width : process.stdout.columns;
	var paddingWidth = cliOptions.largestOptionLength() + 6;
	var stringWidth = totalWidth - paddingWidth;

	var paddingString = '\n' + Array(paddingWidth - 3).join(' ');

	for (var i = 0; i < options.length; i++) {
		var option = options[i];

		// Separate description by width taking words into consideration
		var description = option.description;
		var splitDescription = [];
		while (description) {
			if (description.length <= stringWidth) {
				splitDescription.push(description);
				description = '';
				continue;
			}

			var lastSpaceI = description.lastIndexOf(' ', stringWidth);
			var stringChunk = description.substring(0, lastSpaceI);
			description = description.substring(lastSpaceI + 1);
			splitDescription.push(stringChunk);
		}

		// Reconstruct description with correct padding
		option.description = splitDescription.join(paddingString);
	}
}


/**
 * Function which sets up the commander object with all of our options and customisations.
 * 
 * @returns {undefined}
 */
function setupCliObject () {
	// Set cli options
	cliOptions
		.version(packageJson.version)
		.usage('[options] <component_path ...>')
		.option('-r, --recursive',
			'Whether or not we should recurse and lint dependencies.')
		.option('-d, --dep-paths <paths>',
			'Colon separated list of paths to dependency components. These paths will be used to ' +
			'recurse into installed components.')
		.option('-w, --warn-on-deps',
			'If provided, 3rd party (dependencies) component errors will only result in a warning ' +
			'and not return a fail status code.')
		.option('-l, --lookup-paths <paths>',
			'Colon separated list of paths to check for the existance of missing dependencies. This ' +
			'is used to give the user a hint where they can find dependencies.');

	// Cleanup option strings and re-format them
	formatOptionStrings(cliOptions.options, 100);

	// Add additional info at the bottom of our help
	cliOptions.on('--help', function() {
		var scriptName = path.basename(process.argv[1]);

		console.log('  Examples:');
		console.log('');
		console.log('    Check multiple component entry points');
		console.log('    $ ' + scriptName + ' /path/to/single/component /path/to/another/component');
		console.log('');
		console.log('    Check multiple component entry point which exist in the same folder');
		console.log('    $ ' + scriptName + ' /path/to/multiple/component/folder/*/');
		console.log('');
	});

	// Parse arguments<commit_msg>fixed some of the help text<commit_after>var fs = require('fs');
var path = require('path');
var async = require('async');
var cliOptions = require('commander');

var packageJson = require('../package.json');
var componentHint = require('./component-hint.js');


/**
 * Function which re-formats commander option descriptions to have correct new lines and padding.
 * This makes the output a whole lot cleaner with long description strings, and takes terminal
 * window width into consideration.
 * 
 * @param {Array} options - options array from commander object
 * @param {Integer} width - maximum width for output, this should include padding size
 * @returns {undefined}
 */
function formatOptionStrings (options, width) {
	var totalWidth = (width < process.stdout.columns) ? width : process.stdout.columns;
	var paddingWidth = cliOptions.largestOptionLength() + 6;
	var stringWidth = totalWidth - paddingWidth;

	var paddingString = '\n' + Array(paddingWidth - 3).join(' ');

	for (var i = 0; i < options.length; i++) {
		var option = options[i];

		// Separate description by width taking words into consideration
		var description = option.description;
		var splitDescription = [];
		while (description) {
			if (description.length <= stringWidth) {
				splitDescription.push(description);
				description = '';
				continue;
			}

			var lastSpaceI = description.lastIndexOf(' ', stringWidth);
			var stringChunk = description.substring(0, lastSpaceI);
			description = description.substring(lastSpaceI + 1);
			splitDescription.push(stringChunk);
		}

		// Reconstruct description with correct padding
		option.description = splitDescription.join(paddingString);
	}
}


/**
 * Function which sets up the commander object with all of our options and customisations.
 * 
 * @returns {undefined}
 */
function setupCliObject () {
	// Set cli options
	cliOptions
		.version(packageJson.version)
		.usage('[options] <component_path ...>')
		.option('-r, --recursive',
			'Whether or not we should recurse into local and external dependencies.')
		.option('-d, --dep-paths <paths>',
			'Colon separated list of paths to external dependencies. (default: "./components")')
		.option('-w, --warn-on-deps',
			'If provided, errors caused by external dependencies will only result in a warning ' +
			'and not return a fail status code.')
		.option('-l, --lookup-paths <paths>',
			'Colon separated list of paths to check for the existance of missing local ' +
			'dependencies. This is used to give the user a hint where they can find them.');

	// Cleanup option strings and re-format them
	formatOptionStrings(cliOptions.options, 100);

	// Add additional info at the bottom of our help
	cliOptions.on('--help', function() {
		var scriptName = path.basename(process.argv[1]);

		console.log('  Examples:');
		console.log('');
		console.log('    Check multiple component entry points');
		console.log('    $ ' + scriptName + ' /path/to/single/component /path/to/another/component');
		console.log('');
		console.log('    Check multiple component entry point which exist in the same folder');
		console.log('    $ ' + scriptName + ' /path/to/multiple/component/folder/*/');
		console.log('');
	});

	// Parse arguments
{'fraction_non_alphanumeric': 0.12598791259879125, 'fraction_numerical': 0.0029443669611033626, 'mean_word_length': 3.938026013771997, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1909361', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1752, 'n_words': 615}