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

Exit on parse #169

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
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
9 changes: 6 additions & 3 deletions dist/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ session.prompt = function (options, cb) {
* Gets the full (normal + mode) delimiter
* for this session.
*
* @return {String}
* @return {String} or undefined if there is no delimiter
* @api public
*/

session.fullDelimiter = function () {
var result = this._delimiter + (this._modeDelimiter !== undefined ? this._modeDelimiter : '');
var result;
if (this._delimiter && this._delimiter !== '') {
result = this._delimiter + (this._modeDelimiter !== undefined ? this._modeDelimiter : '');
}
return result;
};

Expand All @@ -157,7 +160,7 @@ session.delimiter = function (str) {
if (str === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im not sure why we are adding this empty space here.

Copy link
Owner

@dthree dthree Aug 8, 2016

Choose a reason for hiding this comment

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

The prompt delimiter is a very touchy subject, and if you look in the issue history, there's a lot of subtle bug fixes involved with it. Be careful before changing things, as seeming fixes can break a lot of other things in this area.


I haven't been able to break out some code to test these things as I've been swamped, so sorry for not giving too much insight. Trying to do that as soon as possible, but I think for now we should just revert instead of piling fixes on fixes which break fixes which require more fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you bet. the PR is here anyways. let me know how I can help.

I did everything I could for now. I believe the ball is in your court now.

Let me know when you revert the changes so that I can re-open the issue with the ability to run prompts inside the parse context.

Copy link
Contributor Author

@alansouzati alansouzati Aug 8, 2016

Choose a reason for hiding this comment

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

I understand that sometimes we need to add fixes that are not necessarily intuitive enough. I tend to add comments around it anytime I have to do things like that.

This way it helps future developers working on the library.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks a lot!! 👍

return this._delimiter;
}
this._delimiter = String(str).trim() + ' ';
this._delimiter = String(str).trim();
if (this.isLocal()) {
this.parent.ui.refresh();
} else {
Expand Down
2 changes: 1 addition & 1 deletion dist/ui.js
Original file line number Diff line number Diff line change
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
16 changes: 8 additions & 8 deletions dist/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion dist/vorpal.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,20 @@ Vorpal.prototype.parse = function (argv, options) {
args[i] = '"' + args[i] + '"';
}
}
if (!options.keepAlive) {
// turn off the delimiter since we are
// not into the vorpal context
result.delimiter('');
}
ui.attach(result);
this.exec(args.join(' '), function (err) {
if (err !== undefined && err !== null) {
throw new Error(err);
}
if (!options.keepAlive) {
// Exits the CLI context as the UI is still attached
this.exec('exit');
}
});
}
}
Expand Down Expand Up @@ -553,7 +562,7 @@ vorpal.prompt = function () {
}
};

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

if (!ssn) {
Expand Down Expand Up @@ -609,6 +618,12 @@ vorpal._prompt = function (data) {
return self;
}

// this means that no delimiter has been specified
// and we should skip the prompt
if (!ssn.fullDelimiter()) {
return undefined;
}

prompt = ui.prompt({
type: 'input',
name: 'command',
Expand Down
10 changes: 6 additions & 4 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ session.prompt = function (options, cb) {
* Gets the full (normal + mode) delimiter
* for this session.
*
* @return {String}
* @return {String} or undefined if there is no delimiter
* @api public
*/

session.fullDelimiter = function () {
var result = this._delimiter +
((this._modeDelimiter !== undefined) ? this._modeDelimiter : '');
var result;
if (this._delimiter && this._delimiter !== '') {
result = this._delimiter + (this._modeDelimiter !== undefined ? this._modeDelimiter : '');
}
return result;
};

Expand All @@ -158,7 +160,7 @@ session.delimiter = function (str) {
if (str === undefined) {
return this._delimiter;
}
this._delimiter = String(str).trim() + ' ';
this._delimiter = String(str).trim();
if (this.isLocal()) {
this.parent.ui.refresh();
} else {
Expand Down
15 changes: 15 additions & 0 deletions lib/vorpal.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,20 @@ Vorpal.prototype.parse = function (argv, options) {
args[i] = `"${args[i]}"`;
}
}
if (!options.keepAlive) {
// turn off the delimiter since we are
// not into the vorpal context
result.delimiter('');
}
ui.attach(result);
this.exec(args.join(' '), function (err) {
if (err !== undefined && err !== null) {
throw new Error(err);
}
if (!options.keepAlive) {
// Exits the CLI context as the UI is still attached
this.exec('exit');
}
});
}
}
Expand Down Expand Up @@ -604,6 +613,12 @@ vorpal._prompt = function (data) {
return self;
}

// this means that no delimiter has been specified
// and we should skip the prompt
if (!ssn.fullDelimiter()) {
return undefined;
}

prompt = ui.prompt({
type: 'input',
name: 'command',
Expand Down