diff --git a/lib/cake.js b/lib/cake.js index b3ec0ba1..0e51a442 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -1,11 +1,15 @@ (function(){ - var coffee, fs, path, print_tasks, tasks; + var coffee, fs, no_such_task, path, print_tasks, tasks; var __hasProp = Object.prototype.hasOwnProperty; // `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript. fs = require('fs'); path = require('path'); coffee = require('coffee-script'); tasks = {}; + no_such_task = function no_such_task(task) { + process.stdio.writeError('No such task: "' + task + '"\n'); + return process.exit(1); + }; // Mixin the Cake functionality. process.mixin({ // Define a task with a name, a description, and the action itself. @@ -18,6 +22,9 @@ }, // Invoke another task in the Cakefile. invoke: function invoke(name) { + if (!(tasks[name])) { + no_such_task(name); + } return tasks[name].action(); } }); @@ -59,10 +66,12 @@ _a = []; _b = args; for (_c = 0; _c < _b.length; _c++) { arg = _b[_c]; - if (!(tasks[arg])) { - throw new Error('No such task: "' + arg + '"'); - } - tasks[arg].action(); + _a.push((function() { + if (!(tasks[arg])) { + no_such_task(arg); + } + return tasks[arg].action(); + }).call(this)); } return _a; }); diff --git a/src/cake.coffee b/src/cake.coffee index b18a8e35..5fb2cfa8 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -6,6 +6,10 @@ coffee: require 'coffee-script' tasks: {} +no_such_task: (task) -> + process.stdio.writeError('No such task: "' + task + '"\n') + process.exit(1) + # Mixin the Cake functionality. process.mixin { @@ -15,6 +19,7 @@ process.mixin { # Invoke another task in the Cakefile. invoke: (name) -> + no_such_task name unless tasks[name] tasks[name].action() } @@ -35,6 +40,6 @@ exports.run: -> eval coffee.compile source return print_tasks() unless args.length for arg in args - throw new Error('No such task: "' + arg + '"') unless tasks[arg] + no_such_task arg unless tasks[arg] tasks[arg].action()