Skip to content

Commit

Permalink
Merge pull request #200 from ccorcos/master
Browse files Browse the repository at this point in the history
Do not attach ui after parse
  • Loading branch information
dthree authored Dec 15, 2016
2 parents 0a6fea5 + 2b3adfe commit 1bab7ed
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 26 deletions.
15 changes: 7 additions & 8 deletions dist/command-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ var CommandInstance = function () {
*/

function CommandInstance() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

var command = _ref.command;
var commandObject = _ref.commandObject;
var args = _ref.args;
var commandWrapper = _ref.commandWrapper;
var callback = _ref.callback;
var downstream = _ref.downstream;
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
command = _ref.command,
commandObject = _ref.commandObject,
args = _ref.args,
commandWrapper = _ref.commandWrapper,
callback = _ref.callback,
downstream = _ref.downstream;

_classCallCheck(this, CommandInstance);

Expand Down
14 changes: 13 additions & 1 deletion dist/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ command.action = function (fn) {
return this;
};

/**
* Let's you compose other funtions to extend the command.
*
* @param {Function} fn
* @return {Command}
* @api public
*/

command.use = function (fn) {
return fn(this);
};

/**
* Defines a function to validate arguments
* before action is performed. Arguments
Expand Down Expand Up @@ -376,7 +388,7 @@ command.hidden = function () {
*/

command.allowUnknownOptions = function () {
var allowUnknownOptions = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
var allowUnknownOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;

allowUnknownOptions = allowUnknownOptions === "false" ? false : allowUnknownOptions;

Expand Down
2 changes: 1 addition & 1 deletion dist/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function Logger(cons) {
// Ugh. We're chopping a line, so we have to look for unfinished
// color assignments and throw them on the next line.
if (matches && matches[matches.length - 1] !== '\\u001b[39m') {
trimmed += '\u001b[39m';
trimmed += '\x1B[39m';
var number = String(matches[matches.length - 1]).slice(7, 9);
color = '\x1B[' + number + 'm';
}
Expand Down
2 changes: 1 addition & 1 deletion dist/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Option = function () {
this.flags = flags;
this.required = ~flags.indexOf('<');
this.optional = ~flags.indexOf('[');
this.bool = ! ~flags.indexOf('-no-');
this.bool = !~flags.indexOf('-no-');
this.autocomplete = autocomplete;
flags = flags.split(/[ ,|]+/);
if (flags.length > 1 && !/^[[<]/.test(flags[1])) {
Expand Down
4 changes: 2 additions & 2 deletions dist/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var UI = function (_EventEmitter) {
function UI() {
_classCallCheck(this, UI);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(UI).call(this));
var _this = _possibleConstructorReturn(this, (UI.__proto__ || Object.getPrototypeOf(UI)).call(this));

var self = _this;

Expand Down Expand Up @@ -193,7 +193,7 @@ var UI = function (_EventEmitter) {
value: function prompt(options, cb) {
var _this2 = this;

var prompt = undefined;
var prompt = void 0;
options = options || {};
if (!this.parent) {
return prompt;
Expand Down
18 changes: 9 additions & 9 deletions dist/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Module dependencies.
*/

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _ = require('lodash');
var minimist = require('minimist');
Expand All @@ -24,7 +24,7 @@ var util = {
parseArgs: function parseArgs(str, opts) {
var reg = /"(.*?)"|'(.*?)'|`(.*?)`|([^\s"]+)/gi;
var arr = [];
var match = undefined;
var match = void 0;
do {
match = reg.exec(str);
if (match !== null) {
Expand All @@ -49,9 +49,9 @@ var util = {
parseCommand: function parseCommand(command, commands) {
var self = this;
var pipes = [];
var match = undefined;
var matchArgs = undefined;
var matchParts = undefined;
var match = void 0;
var matchArgs = void 0;
var matchParts = void 0;

function parsePipes() {
// First, split the command by pipes naively.
Expand Down Expand Up @@ -146,8 +146,8 @@ var util = {
matchCommand: function matchCommand(cmd, cmds) {
var parts = String(cmd).trim().split(' ');

var match = undefined;
var matchArgs = undefined;
var match = void 0;
var matchArgs = void 0;
for (var i = 0; i < parts.length; ++i) {
var subcommand = String(parts.slice(0, parts.length - i).join(' ')).trim();
match = _.find(cmds, { _name: subcommand }) || match;
Expand Down Expand Up @@ -175,8 +175,8 @@ var util = {
if (match) {
var allCommands = _.map(cmds, '_name');
var wordMatch = false;
for (var key in allCommands) {
var _cmd2 = allCommands[key];
for (var _key in allCommands) {
var _cmd2 = allCommands[_key];
var parts2 = String(_cmd2).split(' ');
var cmdParts = String(match.command).split(' ');
var matchAll = true;
Expand Down
6 changes: 3 additions & 3 deletions dist/vorpal.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ Vorpal.prototype.parse = function (argv, options) {
args[i] = '"' + args[i] + '"';
}
}
ui.attach(result);
this.exec(args.join(' '), function (err) {
if (err !== undefined && err !== null) {
throw new Error(err);
}
process.exit(0);
});
}
}
Expand Down Expand Up @@ -540,7 +540,7 @@ vorpal._onKeypress = function (key, value) {
vorpal.prompt = function () {
var _this = this;

var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var userCallback = arguments[1];

return new Promise(function (resolve) {
Expand All @@ -553,7 +553,7 @@ vorpal.prompt = function () {
}
};

var prompt = undefined;
var prompt = void 0;
var ssn = _this.getSessionById(options.sessionId);

if (!ssn) {
Expand Down
12 changes: 12 additions & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ command.action = function (fn) {
return this;
};

/**
* Let's you compose other funtions to extend the command.
*
* @param {Function} fn
* @return {Command}
* @api public
*/

command.use = function (fn) {
return fn(this);
};

/**
* Defines a function to validate arguments
* before action is performed. Arguments
Expand Down
2 changes: 1 addition & 1 deletion lib/vorpal.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ Vorpal.prototype.parse = function (argv, options) {
args[i] = `"${args[i]}"`;
}
}
ui.attach(result);
this.exec(args.join(' '), function (err) {
if (err !== undefined && err !== null) {
throw new Error(err);
}
process.exit(0);
});
}
}
Expand Down

0 comments on commit 1bab7ed

Please sign in to comment.