3 var grunt = require('../grunt');
6 var path = require('path');
10 exports.initCol1 = function(str) {
11 col1len = Math.max(col1len, str.length);
13 exports.initWidths = function() {
14 // Widths for options/tasks table output.
15 exports.widths = [1, col1len, 2, 76 - col1len];
18 // Render an array in table form.
19 exports.table = function(arr) {
20 arr.forEach(function(item) {
21 grunt.log.writetableln(exports.widths, ['', grunt.util._.pad(item[0], col1len), '', item[1]]);
25 // Methods to run, in-order.
38 // Actually display stuff.
39 exports.display = function() {
40 exports.queue.forEach(function(name) { exports[name](); });
44 exports.header = function() {
45 grunt.log.writeln('Grunt: The JavaScript Task Runner (v' + grunt.version + ')');
49 exports.usage = function() {
50 grunt.log.header('Usage');
51 grunt.log.writeln(' ' + path.basename(process.argv[1]) + ' [options] [task [task ...]]');
55 exports.initOptions = function() {
56 // Build 2-column array for table view.
57 exports._options = Object.keys(grunt.cli.optlist).map(function(long) {
58 var o = grunt.cli.optlist[long];
59 var col1 = '--' + (o.negate ? 'no-' : '') + long + (o.short ? ', -' + o.short : '');
60 exports.initCol1(col1);
61 return [col1, o.info];
65 exports.options = function() {
66 grunt.log.header('Options');
67 exports.table(exports._options);
70 exports.optionsFooter = function() {
71 grunt.log.writeln().writelns(
72 'Options marked with * have methods exposed via the grunt API and should ' +
73 'instead be specified inside the Gruntfile wherever possible.'
78 exports.initTasks = function() {
79 // Initialize task system so that the tasks can be listed.
80 grunt.task.init([], {help: true});
82 // Build object of tasks by info (where they were loaded from).
84 Object.keys(grunt.task._tasks).forEach(function(name) {
85 exports.initCol1(name);
86 var task = grunt.task._tasks[name];
87 exports._tasks.push(task);
91 exports.tasks = function() {
92 grunt.log.header('Available tasks');
93 if (exports._tasks.length === 0) {
94 grunt.log.writeln('(no tasks found)');
96 exports.table(exports._tasks.map(function(task) {
98 if (task.multi) { info += ' *'; }
99 return [task.name, info];
102 grunt.log.writeln().writelns(
103 'Tasks run in the order specified. Arguments may be passed to tasks that ' +
104 'accept them by using colons, like "lint:files". Tasks marked with * are ' +
105 '"multi tasks" and will iterate over all sub-targets if no argument is ' +
110 grunt.log.writeln().writelns(
111 'The list of available tasks may change based on tasks directories or ' +
112 'grunt plugins specified in the Gruntfile or via command-line options.'
117 exports.footer = function() {
118 grunt.log.writeln().writeln('For more information, see http://gruntjs.com/');