<commit_before>/*
 * grunt
 * https://github.com/cowboy/grunt
 *
 * Copyright (c) 2012 "Cowboy" <NAME>
 * Licensed under the MIT license.
 * http://benalman.com/about/license/
 */

var path = require('path');
var optlist = grunt.require('cli').optlist;

task.init([], true);

var col1len = 0;

var opts = Object.keys(optlist).map(function(long) {
  var o = optlist[long];
  var col1 = '--' + long + (o.short ? ', -' + o.short : '');
  col1len = Math.max(col1len, col1.length);
  return [col1, o.info];
});

var tasks = Object.keys(task._tasks).map(function(name) {
  col1len = Math.max(col1len, name.length);
  var info = task._tasks[name].info;
  if (task._tasks[name].basic) {
    info += ' *';
  }
  return [name, info];
});

// opts.push(['foo', 'aaa bbb ccc ddd eee'])
// opts.push(['foo', 'aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr sss ttt']);
// opts.push(['foo', 'a b c d e f g h i j k l m n o p q r s t u v w x y z']);
// opts.push(['foo', 'a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z']);
// opts.push(['foo', 'aa b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z']);
// opts.push(['foo', 'aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg hhhhhhhh']);
// opts.push(['foo', 'aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg hhhhhhhh iiiiiiii']);

// Adjust to allow for spacing.
col1len += 2;

// Match as many characters as possible until a set numeric limit has been
// reached, avoiding splitting words whenever possible.
var re = new RegExp('.{1,' + (80 - col1len - 1) + '}(?=\\s|$)', 'g');

// Actually write output, padding and wrapping as necessary..
function writeln(arr) {
  var col1 = arr[0];
  var col2 = arr[1].replace(re, function(s) {
    return '\n' + util.repeat(col1len + 1, ' ') + s.replace(/^\s+/, '');
  }).replace(/^\s+/, '');
  log.writeln(' ' + col1 + util.repeat(col1len - col1.length, ' ') + col2);
}

log.writeln('grunt: a command line build tool for JavaScript projects. (v' + grunt.version + ')');

// Actually write out help screen.
log.header('Usage');
log.writeln(' ' + path.basename(process.argv[1]) + ' [options] [task [task ...]]');

log.header('Options');
opts.forEach(writeln);

log.header('Tasks');
tasks.forEach(writeln);

log.writeln();
[
  'Tasks run in the order specified. Arguments may be passed to tasks that accept',
  'them by using semicolons, like "lint:files". Tasks marked with * are "basic',
  'tasks" and will iterate over config sub-properties if no argument is specified.',
  '',
  'For more information, see https://github.com/cowboy/grunt'
].forEach(log.writeln, log);

process.exit();<commit_msg>Reworking --help to use new log.writelns and log.writetableln methods.<commit_after>/*
 * grunt
 * https://github.com/cowboy/grunt
 *
 * Copyright (c) 2012 "Cowboy" <NAME>
 * Licensed under the MIT license.
 * http://benalman.com/about/license/
 */

var path = require('path');
var optlist = grunt.require('cli').optlist;

task.init([], true);

// Build 2-column array for table view.
var col1len = 0;
var opts = Object.keys(optlist).map(function(long) {
  var o = optlist[long];
  var col1 = '--' + long + (o.short ? ', -' + o.short : '');
  col1len = Math.max(col1len, col1.length);
  return [col1, o.info];
});

var tasks = Object.keys(task._tasks).map(function(name) {
  col1len = Math.max(col1len, name.length);
  var info = task._tasks[name].info;
  if (task._tasks[name].basic) {
    info += ' *';
  }
  return [name, info];
});

// Actually write out help screen.
log.writeln('grunt: a command line build tool for JavaScript projects. (v' + grunt.version + ')');

log.header('Usage');
log.writeln(' ' + path.basename(process.argv[1]) + ' [options] [task [task ...]]');

// Widths for options/tasks table output.
var widths = [1, col1len, 2, 77 - col1len];

log.header('Options');
opts.forEach(function(a) { log.writetableln(widths, ['', a[0], '', a[1]]); });
log.header('Tasks');
tasks.forEach(function(a) { log.writetableln(widths, ['', a[0], '', a[1]]); });

log.writeln().writelns(
  'Tasks run in the order specified. Arguments may be passed to tasks that accept ' +
  'them by using semicolons, like "lint:files". Tasks marked with * are "basic ' +
  'tasks" and will iterate over config sub-properties if no argument is specified.' +
  '\n\n' +
  'For more information, see https://github.com/cowboy/grunt'
);

process.exit();
{'fraction_non_alphanumeric': 0.17937821516439276, 'fraction_numerical': 0.0125251621561172, 'mean_word_length': 3.4989939637826963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 17, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '719167', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1630, 'n_words': 530}