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 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
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
26 changes: 2 additions & 24 deletions dist/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ var UI = function (_EventEmitter) {
} else if (_this.parent.session.cancelCommands) {
// There are commands running if
// cancelCommands function is available.
_this.imprint();
_this.submit('');
_this._sigintCalled = false;
_this._sigintCount = 0;
_this.parent.session.emit('vorpal_command_cancel');
} else if (String(text).trim() !== '') {
_this.imprint();
_this.submit('');
_this._sigintCalled = false;
_this._sigintCount = 0;
Expand Down Expand Up @@ -265,7 +263,7 @@ var UI = function (_EventEmitter) {
inquirer.prompt.prompts.input.prototype.getQuestion = function () {
self._activePrompt = this;
var message = this.opt.message;
if (this.opt.default !== null && this.status !== 'answered') {
if ((this.opt.default || this.opt.default === false) && this.status !== 'answered') {
message += chalk.dim('(' + this.opt.default + ') ');
}
self.inquirerStdout.push(message);
Expand Down Expand Up @@ -536,26 +534,6 @@ var UI = function (_EventEmitter) {
* @api public
*/

}, {
key: 'imprint',
value: function imprint() {
if (!this.parent) {
return this;
}
var val = this._activePrompt.rl.line;
var delimiter = this._lastDelimiter || this.delimiter() || '';
this.log(delimiter + val);
return this;
}

/**
* Redraws the inquirer prompt with a new string.
*
* @param {String} str
* @return {UI}
* @api private
*/

}, {
key: 'refresh',
value: function refresh() {
Expand Down Expand Up @@ -650,4 +628,4 @@ if (!global.__vorpal.ui.exists) {
module.exports = exports = global.__vorpal.ui.exports;
} else {
module.exports = global.__vorpal.ui.exports;
}
}
15 changes: 15 additions & 0 deletions 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 @@ -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
19 changes: 0 additions & 19 deletions lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ class UI extends EventEmitter {
} else if (this.parent.session.cancelCommands) {
// There are commands running if
// cancelCommands function is available.
this.imprint();
this.submit('');
this._sigintCalled = false;
this._sigintCount = 0;
this.parent.session.emit('vorpal_command_cancel');
} else if (String(text).trim() !== '') {
this.imprint();
this.submit('');
this._sigintCalled = false;
this._sigintCount = 0;
Expand Down Expand Up @@ -492,23 +490,6 @@ class UI extends EventEmitter {
return this;
}

/**
* Logs the current delimiter and typed data.
*
* @return {UI}
* @api public
*/

imprint() {
if (!this.parent) {
return this;
}
const val = this._activePrompt.rl.line;
const delimiter = this._lastDelimiter || this.delimiter() || '';
this.log(delimiter + val);
return this;
}

/**
* Redraws the inquirer prompt with a new string.
*
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