Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attach ui after parse #200

Merged
merged 4 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Contributor

@LongLiveCHIEF LongLiveCHIEF Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__proto__ is deprecated, and use is highly discouraged. With the way the command object is currently passed around, this could be destructive for downstream uses.

Should we should be using UI.prototype.constructor instead.


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer the use of the undefined primitive here instead of void 0.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think void 0 is an artifact of the build process.

On doing reviews, makes sure you're looking at src and not dist, as the latter is irrelevant.

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] : {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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