Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rebuild with CoffeeScript 1.3.3

  • Loading branch information...
commit ea0c69854ea3372f02062f081bb7de99c4d55584 1 parent fa52f7a
@arikon arikon authored
View
14 lib/arg.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
var Arg, Cmd, Color, Opt;
Color = require('./color').Color;
@@ -14,11 +15,13 @@ Unnamed entity. From command line arguments passed as list of unnamed values.
@class Presents argument
*/
+
exports.Arg = Arg = (function() {
/**
@constructs
@param {COA.Cmd} cmd parent command
*/
+
function Arg(_cmd) {
this._cmd = _cmd;
this._cmd._args.push(this);
@@ -30,6 +33,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.name = Opt.prototype.name;
/**
@@ -38,6 +42,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.title = Cmd.prototype.title;
/**
@@ -46,6 +51,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.arr = Opt.prototype.arr;
/**
@@ -53,6 +59,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.req = Opt.prototype.req;
/**
@@ -65,6 +72,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.val = Opt.prototype.val;
/**
@@ -74,6 +82,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.def = Opt.prototype.def;
/**
@@ -86,6 +95,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.comp = Cmd.prototype.comp;
/**
@@ -94,6 +104,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.input = Opt.prototype.input;
/**
@@ -102,6 +113,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Arg} this instance (for chainability)
*/
+
Arg.prototype.output = Opt.prototype.output;
Arg.prototype._parse = function(arg, args) {
@@ -131,6 +143,7 @@ exports.Arg = Arg = (function() {
@returns {Q.promise} rejected promise
*/
+
Arg.prototype.reject = Cmd.prototype.reject;
/**
@@ -138,6 +151,7 @@ exports.Arg = Arg = (function() {
@returns {COA.Cmd} parent command
*/
+
Arg.prototype.end = Cmd.prototype.end;
return Arg;
View
117 lib/cmd.js
@@ -1,5 +1,6 @@
+// Generated by CoffeeScript 1.3.3
var Cmd, Color, PATH, Q, UTIL,
- __slice = Array.prototype.slice;
+ __slice = [].slice;
UTIL = require('util');
@@ -17,13 +18,17 @@ Top level entity. Commands may have options and arguments.
@class Presents command
*/
+
exports.Cmd = Cmd = (function() {
/**
@constructs
@param {COA.Cmd} [cmd] parent command
*/
+
function Cmd(cmd) {
- if (!(this instanceof Cmd)) return new Cmd(cmd);
+ if (!(this instanceof Cmd)) {
+ return new Cmd(cmd);
+ }
this._parent(cmd);
this._cmds = [];
this._cmdsByName = {};
@@ -46,6 +51,7 @@ exports.Cmd = Cmd = (function() {
@returns {Object}
*/
+
Cmd.get('api', function() {
var c, _fn,
_this = this;
@@ -64,7 +70,9 @@ exports.Cmd = Cmd = (function() {
});
Cmd.prototype._parent = function(cmd) {
- if (cmd) cmd._cmds.push(this);
+ if (cmd) {
+ cmd._cmds.push(this);
+ }
this._cmd = cmd || this;
return this;
};
@@ -75,9 +83,12 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.name = function(_name) {
this._name = _name;
- if (this._cmd !== this) this._cmd._cmdsByName[_name] = this;
+ if (this._cmd !== this) {
+ this._cmd._cmdsByName[_name] = this;
+ }
return this;
};
@@ -87,6 +98,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.title = function(_title) {
this._title = _title;
return this;
@@ -98,6 +110,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} new subcommand instance
*/
+
Cmd.prototype.cmd = function(cmd) {
if (cmd) {
return cmd._parent(this);
@@ -111,6 +124,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Opt} new option instance
*/
+
Cmd.prototype.opt = function() {
return new (require('./opt').Opt)(this);
};
@@ -120,6 +134,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Opt} new argument instance
*/
+
Cmd.prototype.arg = function() {
return new (require('./arg').Arg)(this);
};
@@ -138,8 +153,11 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.act = function(act, force) {
- if (!act) return this;
+ if (!act) {
+ return this;
+ }
if (!force && this._act) {
this._act.push(act);
} else {
@@ -158,6 +176,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.comp = function(_comp) {
this._comp = _comp;
return this;
@@ -170,6 +189,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.apply = function() {
var args, fn;
fn = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
@@ -182,6 +202,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.helpful = function() {
return this.opt().name('help').title('Help').short('h').long('help').flag().only().act(function() {
return this.usage();
@@ -195,13 +216,16 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.completable = function() {
return this.cmd().name('completion').apply(require('./completion')).end();
};
Cmd.prototype._exit = function(msg, code) {
return process.once('exit', function() {
- if (msg) UTIL.error(msg);
+ if (msg) {
+ UTIL.error(msg);
+ }
return process.exit(code || 0);
});
};
@@ -211,10 +235,13 @@ exports.Cmd = Cmd = (function() {
@returns {String} usage text
*/
+
Cmd.prototype.usage = function() {
var res;
res = [];
- if (this._title) res.push(this._fullTitle());
+ if (this._title) {
+ res.push(this._fullTitle());
+ }
res.push('', 'Usage:');
if (this._cmds.length) {
res.push(['', '', Color('lred', this._fullName()), Color('lblue', 'COMMAND'), Color('lgreen', '[OPTIONS]'), Color('lpurple', '[ARGS]')].join(' '));
@@ -232,7 +259,9 @@ exports.Cmd = Cmd = (function() {
Cmd.prototype._usages = function(os, title) {
var o, res, _i, _len;
- if (!os.length) return;
+ if (!os.length) {
+ return;
+ }
res = ['', title + ':'];
for (_i = 0, _len = os.length; _i < _len; _i++) {
o = os[_i];
@@ -276,11 +305,15 @@ exports.Cmd = Cmd = (function() {
Cmd.prototype._parseCmd = function(argv, unparsed) {
var cmd, i, optSeen;
- if (unparsed == null) unparsed = [];
+ if (unparsed == null) {
+ unparsed = [];
+ }
argv = argv.concat();
optSeen = false;
while (i = argv.shift()) {
- if (!i.indexOf('-')) optSeen = true;
+ if (!i.indexOf('-')) {
+ optSeen = true;
+ }
if (!optSeen && /^\w[\w-_]*$/.test(i) && (cmd = this._cmdsByName[i])) {
return cmd._parseCmd(argv, unparsed);
}
@@ -302,20 +335,30 @@ exports.Cmd = Cmd = (function() {
if (i !== '--' && !i.indexOf('-')) {
if (m = i.match(/^(--\w[\w-_]*)=(.*)$/)) {
i = m[1];
- if (!this._optsByKey[i]._flag) argv.unshift(m[2]);
+ if (!this._optsByKey[i]._flag) {
+ argv.unshift(m[2]);
+ }
}
if (opt = this._ejectOpt(nonParsedOpts, this._optsByKey[i])) {
- if (Q.isRejected(res = opt._parse(argv, opts))) return res;
+ if (Q.isRejected(res = opt._parse(argv, opts))) {
+ return res;
+ }
} else {
return this.reject("Unknown option: " + i);
}
} else {
- if (i === '--') i = argv.splice(0);
+ if (i === '--') {
+ i = argv.splice(0);
+ }
i = Array.isArray(i) ? i : [i];
while (a = i.shift()) {
if (arg = nonParsedArgs.shift()) {
- if (arg._arr) nonParsedArgs.unshift(arg);
- if (Q.isRejected(res = arg._parse(a, args))) return res;
+ if (arg._arr) {
+ nonParsedArgs.unshift(arg);
+ }
+ if (Q.isRejected(res = arg._parse(a, args))) {
+ return res;
+ }
} else {
return this.reject("Unknown argument: " + a);
}
@@ -332,13 +375,15 @@ exports.Cmd = Cmd = (function() {
var i, _i, _len;
for (_i = 0, _len = desc.length; _i < _len; _i++) {
i = desc[_i];
- if (!(i._name in params) && '_def' in i) i._saveVal(params, i._def);
+ if (!(i._name in params) && '_def' in i) {
+ i._saveVal(params, i._def);
+ }
}
return params;
};
Cmd.prototype._processParams = function(params, desc) {
- var i, n, notExists, v, vals, _i, _j, _len, _len2;
+ var i, n, notExists, v, vals, _i, _j, _len, _len1;
notExists = [];
for (_i = 0, _len = desc.length; _i < _len; _i++) {
i = desc[_i];
@@ -349,8 +394,10 @@ exports.Cmd = Cmd = (function() {
}
vals = params[n];
delete params[n];
- if (!Array.isArray(vals)) vals = [vals];
- for (_j = 0, _len2 = vals.length; _j < _len2; _j++) {
+ if (!Array.isArray(vals)) {
+ vals = [vals];
+ }
+ for (_j = 0, _len1 = vals.length; _j < _len1; _j++) {
v = vals[_j];
i._saveVal(params, v);
}
@@ -390,15 +437,18 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} this instance (for chainability)
*/
+
Cmd.prototype.run = function(argv) {
var cb,
_this = this;
- if (argv == null) argv = process.argv.slice(2);
+ if (argv == null) {
+ argv = process.argv.slice(2);
+ }
cb = function(code) {
return function(res) {
- var _ref, _ref2;
+ var _ref, _ref1;
if (res) {
- return _this._exit((_ref = res.stack) != null ? _ref : res.toString(), (_ref2 = res.exitCode) != null ? _ref2 : code);
+ return _this._exit((_ref = res.stack) != null ? _ref : res.toString(), (_ref1 = res.exitCode) != null ? _ref1 : code);
} else {
return _this._exit();
}
@@ -417,12 +467,21 @@ exports.Cmd = Cmd = (function() {
@returns {Q.Promise}
*/
+
Cmd.prototype.invoke = function(cmds, opts, args) {
var _this = this;
- if (cmds == null) cmds = [];
- if (opts == null) opts = {};
- if (args == null) args = {};
- if (typeof cmds === 'string') cmds = cmds.split(' ');
+ if (cmds == null) {
+ cmds = [];
+ }
+ if (opts == null) {
+ opts = {};
+ }
+ if (args == null) {
+ args = {};
+ }
+ if (typeof cmds === 'string') {
+ cmds = cmds.split(' ');
+ }
if (arguments.length < 3) {
if (!Array.isArray(cmds)) {
args = opts;
@@ -431,7 +490,9 @@ exports.Cmd = Cmd = (function() {
}
}
return Q.when(this._parseCmd(cmds), function(p) {
- if (p.argv.length) return _this.reject("Unknown command: " + cmds.join(' '));
+ if (p.argv.length) {
+ return _this.reject("Unknown command: " + cmds.join(' '));
+ }
return Q.fail(_this._do({
cmd: p.cmd,
opts: _this._processParams(opts, _this._opts),
@@ -455,6 +516,7 @@ exports.Cmd = Cmd = (function() {
@returns {Q.promise} rejected promise
*/
+
Cmd.prototype.reject = function(reason) {
return Q.reject(reason);
};
@@ -464,6 +526,7 @@ exports.Cmd = Cmd = (function() {
@returns {COA.Cmd} parent command
*/
+
Cmd.prototype.end = function() {
return this._cmd;
};
View
1  lib/coa.js
@@ -1,2 +1,3 @@
+// Generated by CoffeeScript 1.3.3
exports.Cmd = require('./cmd').Cmd;
View
1  lib/color.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
var colors;
colors = {
View
14 lib/completion.js
@@ -1,7 +1,9 @@
+// Generated by CoffeeScript 1.3.3
/**
Most of the code adopted from the npm package shell completion code.
See https://github.com/isaacs/npm/blob/master/lib/completion.js
*/
+
var Q, complete, dumpScript, escape, getOpts, unescape;
Q = require('q');
@@ -42,7 +44,9 @@ dumpScript = function(name) {
defer = Q.defer();
fs.readFile(path.resolve(__dirname, 'completion.sh'), 'utf8', function(err, d) {
var onError;
- if (err) return defer.reject(err);
+ if (err) {
+ return defer.reject(err);
+ }
d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^\#\!.*?\n/, '');
onError = function(err) {
if (err.errno === require('constants').EPIPE) {
@@ -75,7 +79,9 @@ getOpts = function(argv) {
i--;
}
partialWord = unescape(partialWord.substr(0, i));
- if (partialWord) partialWords.push(partialWord);
+ if (partialWord) {
+ partialWords.push(partialWord);
+ }
return {
line: line,
w: w,
@@ -101,7 +107,9 @@ complete = function(cmd, opts) {
compls = Object.keys(cmd._optsByKey);
}
}
- if (!(o = opts.partialWords[opts.w - 1]).indexOf('-')) optWord = o;
+ if (!(o = opts.partialWords[opts.w - 1]).indexOf('-')) {
+ optWord = o;
+ }
if (optWord && (opt = cmd._optsByKey[optWord])) {
if (!opt._flag && opt._comp) {
compls = Q.join(compls, Q.when(opt._comp(opts), function(c, o) {
View
31 lib/opt.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
var Cmd, Color, Opt, Q, fs;
fs = require('fs');
@@ -16,11 +17,13 @@ Named entity. Options may have short and long keys for use from command line.
@class Presents option
*/
+
exports.Opt = Opt = (function() {
/**
@constructs
@param {COA.Cmd} cmd parent command
*/
+
function Opt(_cmd) {
this._cmd = _cmd;
this._cmd._opts.push(this);
@@ -32,6 +35,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.name = function(_name) {
this._name = _name;
return this;
@@ -43,6 +47,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.title = Cmd.prototype.title;
/**
@@ -51,6 +56,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.short = function(_short) {
this._short = _short;
return this._cmd._optsByKey['-' + _short] = this;
@@ -62,6 +68,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.long = function(_long) {
this._long = _long;
return this._cmd._optsByKey['--' + _long] = this;
@@ -72,6 +79,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.flag = function() {
this._flag = true;
return this;
@@ -83,6 +91,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.arr = function() {
this._arr = true;
return this;
@@ -93,6 +102,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.req = function() {
this._req = true;
return this;
@@ -104,6 +114,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.only = function() {
this._only = true;
return this;
@@ -119,6 +130,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.val = function(_val) {
this._val = _val;
return this;
@@ -131,6 +143,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.def = function(_def) {
this._def = _def;
return this;
@@ -142,6 +155,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.input = function() {
process.stdin.pause();
return this.def(process.stdin).val(function(v) {
@@ -168,6 +182,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.output = function() {
return this.def(process.stdout).val(function(v) {
if (typeof v === 'string') {
@@ -199,6 +214,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.act = function(act) {
var name, opt;
opt = this;
@@ -235,11 +251,14 @@ exports.Opt = Opt = (function() {
@returns {COA.Opt} this instance (for chainability)
*/
+
Opt.prototype.comp = Cmd.prototype.comp;
Opt.prototype._saveVal = function(opts, val) {
var _name;
- if (this._val) val = this._val(val);
+ if (this._val) {
+ val = this._val(val);
+ }
if (this._arr) {
(opts[_name = this._name] || (opts[_name] = [])).push(val);
} else {
@@ -262,12 +281,16 @@ exports.Opt = Opt = (function() {
nameStr = this._name.toUpperCase();
if (this._short) {
res.push('-', Color('lgreen', this._short));
- if (!this._flag) res.push(' ' + nameStr);
+ if (!this._flag) {
+ res.push(' ' + nameStr);
+ }
res.push(', ');
}
if (this._long) {
res.push('--', Color('green', this._long));
- if (!this._flag) res.push('=' + nameStr);
+ if (!this._flag) {
+ res.push('=' + nameStr);
+ }
}
res.push(' : ', this._title);
return res.join('');
@@ -286,6 +309,7 @@ exports.Opt = Opt = (function() {
@returns {Q.promise} rejected promise
*/
+
Opt.prototype.reject = Cmd.prototype.reject;
/**
@@ -293,6 +317,7 @@ exports.Opt = Opt = (function() {
@returns {COA.Cmd} parent command
*/
+
Opt.prototype.end = Cmd.prototype.end;
return Opt;
View
1  lib/shell.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
exports.unescape = function(w) {
w = w.charAt(0) === '"' ? w.replace(/^"|([^\\])"$/g, '$1') : w.replace(/\\ /g, ' ');
Please sign in to comment.
Something went wrong with that request. Please try again.