diff --git a/lib/coffee-script.js b/lib/coffee-script.js index f1a4f4d3..e6c89a16 100755 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -25,7 +25,6 @@ if (options.fileName) { err.message = "In " + options.fileName + ", " + err.message; } - console.error(err.toString()); throw err; } }; diff --git a/lib/command.js b/lib/command.js index 8f60d5c3..46805971 100644 --- a/lib/command.js +++ b/lib/command.js @@ -2,14 +2,13 @@ var ALL_SWITCHES, BANNER, CoffeeScript, DEPRECATED_SWITCHES, EventEmitter, SWITCHES, compileOptions, compileScript, compileScripts, compileStdio, exec, fs, helpers, lint, optionParser, optparse, opts, parseOptions, path, printTokens, sources, spawn, usage, version, watch, writeJs, _ref; fs = require('fs'); path = require('path'); + helpers = require('./helpers'); optparse = require('./optparse'); CoffeeScript = require('./coffee-script'); - helpers = require('./helpers'); _ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec; EventEmitter = require('events').EventEmitter; helpers.extend(CoffeeScript, new EventEmitter); - global.CoffeeScript = CoffeeScript; - BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee'; + BANNER = 'Usage: coffee [options] path/to/script.coffee'; SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-b', '--bare', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']]; DEPRECATED_SWITCHES = [['--no-wrap', 'compile without the top-level function wrapper']]; ALL_SWITCHES = SWITCHES.concat(DEPRECATED_SWITCHES); @@ -218,7 +217,7 @@ }; }; usage = function() { - console.log((new optparse.OptionParser(SWITCHES)).help()); + console.log((new optparse.OptionParser(SWITCHES, BANNER)).help()); return process.exit(0); }; version = function() { diff --git a/lib/optparse.js b/lib/optparse.js index c92b98da..f90c96fb 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -2,8 +2,8 @@ var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments; exports.OptionParser = (function() { OptionParser = (function() { - function OptionParser(rules, banner) { - this.banner = banner; + function OptionParser(rules, _arg) { + this.banner = _arg; this.rules = buildRules(rules); return this; } diff --git a/src/command.coffee b/src/command.coffee index f8b750c0..aced312e 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -7,22 +7,18 @@ # External dependencies. fs = require 'fs' path = require 'path' +helpers = require './helpers' optparse = require './optparse' CoffeeScript = require './coffee-script' -helpers = require './helpers' {spawn, exec} = require 'child_process' {EventEmitter} = require 'events' -# Allow CoffeeScript to emit Node.js events, and add it to global scope. +# Allow CoffeeScript to emit Node.js events. helpers.extend CoffeeScript, new EventEmitter -global.CoffeeScript = CoffeeScript # The help banner that is printed when `coffee` is called without arguments. BANNER = ''' - coffee compiles CoffeeScript source files into JavaScript. - - Usage: - coffee path/to/script.coffee + Usage: coffee [options] path/to/script.coffee ''' # The list of all the valid option flags that `coffee` knows how to handle. @@ -64,7 +60,7 @@ exports.run = -> return version() if opts.version return require './repl' if opts.interactive return compileStdio() if opts.stdio - return compileScript null, sources[0] if opts.eval + return compileScript null, sources[0] if opts.eval return require './repl' unless sources.length separator = sources.indexOf '--' flags = [] @@ -195,7 +191,7 @@ compileOptions = (fileName) -> {fileName, bare: opts.bare or opts['no-wrap']} # Print the `--help` usage message and exit. Deprecated switches are not # shown. usage = -> - console.log (new optparse.OptionParser SWITCHES).help() + console.log (new optparse.OptionParser SWITCHES, BANNER).help() process.exit 0 # Print the `--version` message and exit. diff --git a/src/optparse.coffee b/src/optparse.coffee index 545ce140..a760936e 100644 --- a/src/optparse.coffee +++ b/src/optparse.coffee @@ -13,9 +13,8 @@ exports.OptionParser = class OptionParser # [short-flag, long-flag, description] # # Along with an an optional banner for the usage help. - constructor: (rules, banner) -> - @banner = banner - @rules = buildRules rules + constructor: (rules, @banner) -> + @rules = buildRules rules # Parse the list of arguments, populating an `options` object with all of the # specified options, and returning it. `options.arguments` will be an array