diff --git a/lib/grunt.js b/lib/grunt.js index 072ca24b3..f537af861 100644 --- a/lib/grunt.js +++ b/lib/grunt.js @@ -111,10 +111,16 @@ grunt.tasks = function(tasks, options, done) { task.init(tasks, options); verbose.writeln(); - if (!tasksSpecified) { - verbose.writeln('No tasks specified, running default tasks.'); + + if (!grunt.cli.options.tasklist) { + if (!tasksSpecified) { + verbose.writeln('No tasks specified, running default tasks.'); + } + verbose.writeflags(tasks, 'Running tasks'); + } + else { + verbose.writeln('Listing registered tasks...\n'); } - verbose.writeflags(tasks, 'Running tasks'); // Handle otherwise unhandleable (probably asynchronous) exceptions. var uncaughtHandler = function(e) { @@ -147,10 +153,16 @@ grunt.tasks = function(tasks, options, done) { } }); - // Execute all tasks, in order. Passing each task individually in a forEach - // allows the error callback to execute multiple times. - tasks.forEach(function(name) { task.run(name); }); - // Run tasks async internally to reduce call-stack, per: - // https://github.com/gruntjs/grunt/pull/1026 - task.start({asyncDone: true}); + if (!grunt.cli.options.tasklist) { + // Execute all tasks, in order. Passing each task individually in a forEach + // allows the error callback to execute multiple times. + tasks.forEach(function(name) { task.run(name); }); + // Run tasks async internally to reduce call-stack, per: + // https://github.com/gruntjs/grunt/pull/1026 + task.start({asyncDone: true}); + } + else { + // Do not run the registered tasks but just output them as JSON. + console.log(grunt.task._tasks); + } };