Permalink
Browse files

Breaking this bastard up.

  • Loading branch information...
1 parent 8d0862f commit 28cd913527ddf4f468b88d6100850d20ec8e5935 @mde mde committed May 23, 2011
Showing with 107 additions and 93 deletions.
  1. +6 −4 Makefile
  2. +5 −84 lib/jake.js → bin/jake
  3. +86 −0 lib/parseopts.js
  4. +10 −5 package.json
View
@@ -1,5 +1,5 @@
#
-# Node-Jake JavaScript build tool
+# Jake JavaScript build tool
# Copyright 2112 Matthew Eernisse (mde@fleegix.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,16 +15,18 @@
# limitations under the License.
#
-.PHONY: all build install clean uninstall
+.PHONY: all build install clean uninstall
all: build
build:
@echo 'Jake built.'
install:
- @cp ./lib/jake.js /usr/local/bin/jake && \
- chmod 755 /usr/local/bin/jake && \
+ @mkdir -p /usr/local/lib/node_modules/jake && \
+ cp -R ./* /usr/local/lib/node_modules/jake/ && \
+ ln -snf /usr/local/lib/node_modules/jake/bin/jake /usr/local/bin/jake && \
+ chmod 755 /usr/local/lib/node_modules/jake/bin/jake && \
echo 'Jake installed.'
clean:
View
@@ -23,8 +23,8 @@ var JAKE_VERSION = '0.1.12'
, fs = require('fs')
, path = require('path')
, sys = require('sys')
+ , parseopts = require('../lib/parseopts')
, usage
- , parseopts = {}
, optsReg
, Parser
, parsed
@@ -39,6 +39,7 @@ var JAKE_VERSION = '0.1.12'
, exists
, tasks;
+
process.addListener('uncaughtException', function (err) {
var msg;
console.error('jake aborted.');
@@ -94,89 +95,6 @@ usage = ''
+ ' -V, --version Outputs Jake version\n'
+ '';
-/**
- * @constructor
- * Parses a list of command-line args into a key/value object of
- * options and an array of positional commands.
- * @ param {Array} opts A list of options in the following format:
- * [{full: 'foo', abbr: 'f'}, {full: 'bar', abbr: 'b'}]]
- */
-parseopts.Parser = function (opts) {
- // Positional commands parse out of the args
- this.cmds = [];
- // A key/value object of matching options parsed out of the args
- this.opts = {};
-
- // Data structures used for parsing
- this.reg = [];
- this.shortOpts = {};
- this.longOpts = {};
-
- var item;
- for (var i = 0, ii = opts.length; i < ii; i++) {
- item = opts[i];
- this.shortOpts[item.abbr] = item.full;
- this.longOpts[item.full] = item.full;
- }
- this.reg = opts;
-};
-
-parseopts.Parser.prototype = new function () {
-
- /**
- * Parses an array of arguments into options and positional commands
- * Any matcthing opts end up in a key/value object keyed by the 'full'
- * name of the option. Any args that aren't passed as options end up in
- * an array of positional commands.
- * Any options passed without a value end up with a value of null
- * in the key/value object of options
- * If the user passes options that are not defined in the list passed
- * to the constructor, the parser throws an error 'Unknown option.'
- * @param {Array} args The command-line args to parse
- */
- this.parse = function (args) {
- var cmds = []
- , opts = {}
- , arg
- , argName
- , argItems;
-
- while (args.length) {
- arg = args.shift();
- if (arg.indexOf('--') == 0) {
- argItems = arg.split('=');
- argName = this.longOpts[argItems[0].substr(2)];
- if (argName) {
- // If there's no attached value, value is null
- opts[argName] = argItems[1] || true;
- }
- else {
- throw new Error('Unknown option "' + argItems[0] + '"');
- }
- }
- else if (arg.indexOf('-') == 0) {
- argName = this.shortOpts[arg.substr(1)];
- if (argName) {
- // If there is no following item, or the next item is
- // another opt, value is null
- opts[argName] = (!args[0] || (args[0].indexOf('-') == 0)) ?
- true : args.shift();
- }
- else {
- throw new Error('Unknown option "' + arg + '"');
- }
- }
- else {
- cmds.push(arg);
- }
- }
-
- this.cmds = cmds;
- this.opts = opts;
- };
-
-};
-
/**
* @namespace
* The main namespace for Jake
@@ -727,6 +645,9 @@ optsReg = [
, { full: 'version'
, abbr: 'V'
}
+, { full: 'environment'
+ , abbr: 'e'
+ }
];
Parser = new parseopts.Parser(optsReg);
View
@@ -0,0 +1,86 @@
+var parseopts = {};
+
+/**
+ * @constructor
+ * Parses a list of command-line args into a key/value object of
+ * options and an array of positional commands.
+ * @ param {Array} opts A list of options in the following format:
+ * [{full: 'foo', abbr: 'f'}, {full: 'bar', abbr: 'b'}]]
+ */
+parseopts.Parser = function (opts) {
+ // Positional commands parse out of the args
+ this.cmds = [];
+ // A key/value object of matching options parsed out of the args
+ this.opts = {};
+
+ // Data structures used for parsing
+ this.reg = [];
+ this.shortOpts = {};
+ this.longOpts = {};
+
+ var item;
+ for (var i = 0, ii = opts.length; i < ii; i++) {
+ item = opts[i];
+ this.shortOpts[item.abbr] = item.full;
+ this.longOpts[item.full] = item.full;
+ }
+ this.reg = opts;
+};
+
+parseopts.Parser.prototype = new function () {
+
+ /**
+ * Parses an array of arguments into options and positional commands
+ * Any matcthing opts end up in a key/value object keyed by the 'full'
+ * name of the option. Any args that aren't passed as options end up in
+ * an array of positional commands.
+ * Any options passed without a value end up with a value of null
+ * in the key/value object of options
+ * If the user passes options that are not defined in the list passed
+ * to the constructor, the parser throws an error 'Unknown option.'
+ * @param {Array} args The command-line args to parse
+ */
+ this.parse = function (args) {
+ var cmds = []
+ , opts = {}
+ , arg
+ , argName
+ , argItems;
+
+ while (args.length) {
+ arg = args.shift();
+ if (arg.indexOf('--') == 0) {
+ argItems = arg.split('=');
+ argName = this.longOpts[argItems[0].substr(2)];
+ if (argName) {
+ // If there's no attached value, value is null
+ opts[argName] = argItems[1] || true;
+ }
+ else {
+ throw new Error('Unknown option "' + argItems[0] + '"');
+ }
+ }
+ else if (arg.indexOf('-') == 0) {
+ argName = this.shortOpts[arg.substr(1)];
+ if (argName) {
+ // If there is no following item, or the next item is
+ // another opt, value is null
+ opts[argName] = (!args[0] || (args[0].indexOf('-') == 0)) ?
+ true : args.shift();
+ }
+ else {
+ throw new Error('Unknown option "' + arg + '"');
+ }
+ }
+ else {
+ cmds.push(arg);
+ }
+ }
+
+ this.cmds = cmds;
+ this.opts = opts;
+ };
+
+};
+
+module.exports = parseopts;
View
@@ -1,6 +1,11 @@
-{ "name" : "jake"
-, "version" : "0.1.12"
-, "author" : "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)"
-, "main" : "./lib/jake"
-, "bin" : { "jake" : "./lib/jake.js" }
+{ "name": "jake"
+, "version": "0.1.12"
+, "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)"
+, "bin": { "jake": "./bin/jake" }
+, "main": "./lib"
+, "repository": {
+ "type": "git"
+ , "url": "https://github.com/mde/jake.git"
+ }
+, "preferGlobal": true
}

0 comments on commit 28cd913

Please sign in to comment.