round 2, light refactors.
This commit is contained in:
parent
bb05e07e4e
commit
f6a8d4c074
|
@ -25,7 +25,6 @@
|
|||
if (options.fileName) {
|
||||
err.message = "In " + options.fileName + ", " + err.message;
|
||||
}
|
||||
console.error(err.toString());
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -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.
|
||||
|
|
|
@ -13,8 +13,7 @@ exports.OptionParser = class OptionParser
|
|||
# [short-flag, long-flag, description]
|
||||
#
|
||||
# Along with an an optional banner for the usage help.
|
||||
constructor: (rules, banner) ->
|
||||
@banner = banner
|
||||
constructor: (rules, @banner) ->
|
||||
@rules = buildRules rules
|
||||
|
||||
# Parse the list of arguments, populating an `options` object with all of the
|
||||
|
|
Loading…
Reference in New Issue