making 'no such task' errors a little nicer

This commit is contained in:
Jeremy Ashkenas
2010-02-17 20:37:30 -05:00
parent fbfa12c733
commit 8ff977dc65
2 changed files with 20 additions and 6 deletions

View File

@@ -1,11 +1,15 @@
(function(){ (function(){
var coffee, fs, path, print_tasks, tasks; var coffee, fs, no_such_task, path, print_tasks, tasks;
var __hasProp = Object.prototype.hasOwnProperty; var __hasProp = Object.prototype.hasOwnProperty;
// `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript. // `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript.
fs = require('fs'); fs = require('fs');
path = require('path'); path = require('path');
coffee = require('coffee-script'); coffee = require('coffee-script');
tasks = {}; 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. // Mixin the Cake functionality.
process.mixin({ process.mixin({
// Define a task with a name, a description, and the action itself. // Define a task with a name, a description, and the action itself.
@@ -18,6 +22,9 @@
}, },
// Invoke another task in the Cakefile. // Invoke another task in the Cakefile.
invoke: function invoke(name) { invoke: function invoke(name) {
if (!(tasks[name])) {
no_such_task(name);
}
return tasks[name].action(); return tasks[name].action();
} }
}); });
@@ -59,10 +66,12 @@
_a = []; _b = args; _a = []; _b = args;
for (_c = 0; _c < _b.length; _c++) { for (_c = 0; _c < _b.length; _c++) {
arg = _b[_c]; arg = _b[_c];
if (!(tasks[arg])) { _a.push((function() {
throw new Error('No such task: "' + arg + '"'); if (!(tasks[arg])) {
} no_such_task(arg);
tasks[arg].action(); }
return tasks[arg].action();
}).call(this));
} }
return _a; return _a;
}); });

View File

@@ -6,6 +6,10 @@ coffee: require 'coffee-script'
tasks: {} tasks: {}
no_such_task: (task) ->
process.stdio.writeError('No such task: "' + task + '"\n')
process.exit(1)
# Mixin the Cake functionality. # Mixin the Cake functionality.
process.mixin { process.mixin {
@@ -15,6 +19,7 @@ process.mixin {
# Invoke another task in the Cakefile. # Invoke another task in the Cakefile.
invoke: (name) -> invoke: (name) ->
no_such_task name unless tasks[name]
tasks[name].action() tasks[name].action()
} }
@@ -35,6 +40,6 @@ exports.run: ->
eval coffee.compile source eval coffee.compile source
return print_tasks() unless args.length return print_tasks() unless args.length
for arg in args for arg in args
throw new Error('No such task: "' + arg + '"') unless tasks[arg] no_such_task arg unless tasks[arg]
tasks[arg].action() tasks[arg].action()