From e29657682fbb78d717b3206b52662000fb77c84c Mon Sep 17 00:00:00 2001 From: Alan Souza Date: Tue, 2 Aug 2016 23:38:58 -0700 Subject: [PATCH 1/5] Exit on parse --- dist/option.js | 2 +- dist/ui.js | 2 +- dist/util.js | 16 ++++++++-------- dist/vorpal.js | 4 +++- lib/vorpal.js | 2 ++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dist/option.js b/dist/option.js index 4d130eff..d801c6b5 100755 --- a/dist/option.js +++ b/dist/option.js @@ -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])) { diff --git a/dist/ui.js b/dist/ui.js index b09174e5..f8dc342d 100755 --- a/dist/ui.js +++ b/dist/ui.js @@ -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; diff --git a/dist/util.js b/dist/util.js index 2d5126a5..e14deec9 100755 --- a/dist/util.js +++ b/dist/util.js @@ -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) { @@ -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. @@ -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; @@ -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; diff --git a/dist/vorpal.js b/dist/vorpal.js index a103f270..a5aafcfc 100755 --- a/dist/vorpal.js +++ b/dist/vorpal.js @@ -167,6 +167,8 @@ Vorpal.prototype.parse = function (argv, options) { this.exec(args.join(' '), function (err) { if (err !== undefined && err !== null) { throw new Error(err); + // Exits the CLI context as the UI is still attached + this.exec('exit'); } }); } @@ -553,7 +555,7 @@ vorpal.prompt = function () { } }; - var prompt = undefined; + var prompt = void 0; var ssn = _this.getSessionById(options.sessionId); if (!ssn) { diff --git a/lib/vorpal.js b/lib/vorpal.js index d23a2a56..fd8fdfa6 100755 --- a/lib/vorpal.js +++ b/lib/vorpal.js @@ -167,6 +167,8 @@ Vorpal.prototype.parse = function (argv, options) { this.exec(args.join(' '), function (err) { if (err !== undefined && err !== null) { throw new Error(err); + // Exits the CLI context as the UI is still attached + this.exec('exit'); } }); } From 4359f43bb3c2100563fd5847b616e6e17ddf676e Mon Sep 17 00:00:00 2001 From: Alan Souza Date: Mon, 8 Aug 2016 11:46:38 -0700 Subject: [PATCH 2/5] Added keepAlive option. Fixed wrong place for check --- dist/vorpal.js | 6 ++++-- lib/vorpal.js | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dist/vorpal.js b/dist/vorpal.js index a5aafcfc..9bfaefd8 100755 --- a/dist/vorpal.js +++ b/dist/vorpal.js @@ -167,8 +167,10 @@ Vorpal.prototype.parse = function (argv, options) { this.exec(args.join(' '), function (err) { if (err !== undefined && err !== null) { throw new Error(err); - // Exits the CLI context as the UI is still attached - this.exec('exit'); + if (!options.keepAlive) { + // Exits the CLI context as the UI is still attached + this.exec('exit'); + } } }); } diff --git a/lib/vorpal.js b/lib/vorpal.js index fd8fdfa6..077b7a3a 100755 --- a/lib/vorpal.js +++ b/lib/vorpal.js @@ -167,7 +167,9 @@ Vorpal.prototype.parse = function (argv, options) { this.exec(args.join(' '), function (err) { if (err !== undefined && err !== null) { throw new Error(err); - // Exits the CLI context as the UI is still attached + } + if (!options.keepAlive) { + // Exits the CLI context as the UI is still attached this.exec('exit'); } }); From d32502d99e7bf8a26f8a3ce2e97d97b9d893927d Mon Sep 17 00:00:00 2001 From: Alan Souza Date: Mon, 8 Aug 2016 14:01:04 -0700 Subject: [PATCH 3/5] Skip delimiter for keepAlive false --- dist/session.js | 9 ++++++--- dist/vorpal.js | 19 +++++++++++++++---- lib/session.js | 10 ++++++---- lib/vorpal.js | 11 +++++++++++ 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/dist/session.js b/dist/session.js index 68e14652..96c98931 100755 --- a/dist/session.js +++ b/dist/session.js @@ -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; }; @@ -157,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 { diff --git a/dist/vorpal.js b/dist/vorpal.js index 9bfaefd8..5195f838 100755 --- a/dist/vorpal.js +++ b/dist/vorpal.js @@ -163,14 +163,19 @@ 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'); - } + } + if (!options.keepAlive) { + // Exits the CLI context as the UI is still attached + this.exec('exit'); } }); } @@ -613,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', diff --git a/lib/session.js b/lib/session.js index 058deb3c..88b4c36e 100755 --- a/lib/session.js +++ b/lib/session.js @@ -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; }; @@ -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 { diff --git a/lib/vorpal.js b/lib/vorpal.js index 077b7a3a..17313404 100755 --- a/lib/vorpal.js +++ b/lib/vorpal.js @@ -163,6 +163,11 @@ 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) { @@ -608,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', From b100c5ee97294821b9541c69607d8f76db4ed583 Mon Sep 17 00:00:00 2001 From: Alan Souza Date: Thu, 5 Jan 2017 15:03:28 -0800 Subject: [PATCH 4/5] Removed imprint support --- lib/ui.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/ui.js b/lib/ui.js index e049ed4a..1664ead9 100755 --- a/lib/ui.js +++ b/lib/ui.js @@ -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; @@ -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. * From 365d1fbbccca91d33ef243c956931344c6b02669 Mon Sep 17 00:00:00 2001 From: Alan Souza Date: Thu, 5 Jan 2017 15:04:43 -0800 Subject: [PATCH 5/5] removed imprint from dist folder --- dist/ui.js | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/dist/ui.js b/dist/ui.js index 82dca070..0f5348b3 100755 --- a/dist/ui.js +++ b/dist/ui.js @@ -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; @@ -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() { @@ -650,4 +628,4 @@ if (!global.__vorpal.ui.exists) { module.exports = exports = global.__vorpal.ui.exports; } else { module.exports = global.__vorpal.ui.exports; -} \ No newline at end of file +}