From 1d7a3b4d0fd6fc02b02cae597d1be9e91e8e6c20 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sun, 13 Nov 2011 14:53:41 -0500 Subject: [PATCH] Adding 'No such option' output to parallel 'No such task' (fixes #1862) --- lib/coffee-script/cake.js | 14 ++++++++++++-- src/cake.coffee | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index a1d36939..75398f6a 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -1,5 +1,5 @@ (function() { - var CoffeeScript, cakefileDirectory, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; + var CoffeeScript, cakefileDirectory, fs, helpers, missingOption, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; fs = require('fs'); @@ -50,7 +50,12 @@ }); oparse = new optparse.OptionParser(switches); if (!args.length) return printTasks(); - options = oparse.parse(args); + console.log(args); + try { + options = oparse.parse(args); + } catch (e) { + return missingOption(("" + e).match(/option: (.+)/)[1]); + } _ref = options.arguments; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -73,6 +78,11 @@ if (switches.length) return console.log(oparse.help()); }; + missingOption = function(option) { + console.log("No such option: \"" + option + "\""); + return process.exit(1); + }; + missingTask = function(task) { console.log("No such task: \"" + task + "\""); return process.exit(1); diff --git a/src/cake.coffee b/src/cake.coffee index be5e71a9..8356f674 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -41,8 +41,8 @@ helpers.extend global, # Run `cake`. Executes all of the tasks you pass, in order. Note that Node's # asynchrony may cause tasks to execute in a different order than you'd expect. -# If no tasks are passed, print the help screen. Keep a reference to the -# original directory name, when running Cake tasks from subdirectories. +# If no tasks are passed, print the help screen. Keep a reference to the +# original directory name, when running Cake tasks from subdirectories. exports.run = -> global.__originalDirname = fs.realpathSync '.' process.chdir cakefileDirectory __originalDirname @@ -50,7 +50,11 @@ exports.run = -> CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile' oparse = new optparse.OptionParser switches return printTasks() unless args.length - options = oparse.parse(args) + console.log args + try + options = oparse.parse(args) + catch e + return missingOption "#{e}".match(/option: (.+)/)[1] invoke arg for arg in options.arguments # Display the list of Cake tasks in a format similar to `rake -T` @@ -63,12 +67,17 @@ printTasks = -> console.log "cake #{name}#{spaces} #{desc}" console.log oparse.help() if switches.length +# Print an error and exit when attempting to use an invalid option. +missingOption = (option) -> + console.log "No such option: \"#{option}\"" + process.exit 1 + # Print an error and exit when attempting to call an undefined task. missingTask = (task) -> console.log "No such task: \"#{task}\"" process.exit 1 -# When `cake` is invoked, search in the current and all parent directories +# When `cake` is invoked, search in the current and all parent directories # to find the relevant Cakefile. cakefileDirectory = (dir) -> return dir if path.existsSync path.join dir, 'Cakefile'