lib/cli.js
function formatOptionStrings(options, width) {
	var totalWidth = (width < process.stdout.columns) ? width : process.stdout.columns;
	var paddingWidth = cliOptions.largestOptionLength() + 6;
	var stringWidth = totalWidth - paddingWidth;
	if (stringWidth <= 0) {
		return;
	}

	var paddingString = '\n' + (new 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);
			if (lastSpaceI < 0) {
				splitDescription.push(description);
				description = "";
				break;
			}

			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 formatOptionStrings(options, width) {
	var totalWidth = (width < process.stdout.columns) ? width : process.stdout.columns;
	var paddingWidth = cliOptions.largestOptionLength() + 6;
	var stringWidth = totalWidth - paddingWidth;
	if (stringWidth <= 0) {
		return;
	}

	var paddingString = '\n' + (new 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);
			if (lastSpaceI < 0) {
				splitDescription.push(description);
				description = "";
				break;
			}

			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 formatOptionStrings ( options , width ) { var totalWidth = ( width < process . stdout . columns ) ? width : process . stdout . columns ; var paddingWidth = cliOptions . largestOptionLength ( ) + 6 ; var stringWidth = totalWidth - paddingWidth ; if ( stringWidth <= 0 ) { return ; } var paddingString = '\n' + ( new 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 ) ; if ( lastSpaceI < 0 ) { splitDescription . push ( description ) ; description = "" ; break ; } 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 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 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 .