1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

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(){
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;
});

View file

@ -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()