From 4c5cb95209d6ee47b70cadb1d4c417d88e9ec909 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 2 Mar 2017 07:44:24 -0500 Subject: [PATCH] refactor: extract method for cmd interpreter --- lib/dashboard/console.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/dashboard/console.js b/lib/dashboard/console.js index f3901874..c510f204 100644 --- a/lib/dashboard/console.js +++ b/lib/dashboard/console.js @@ -10,15 +10,7 @@ Console.prototype.runCode = function(code) { RunCode.doEval(code); // jshint ignore:line }; -Console.prototype.executeCmd = function(cmd, callback) { - var plugin, pluginOutput; - var plugins = this.plugins.getPluginsFor('console'); - for (var i = 0; i < plugins.length; i++) { - plugin = plugins[i]; - pluginOutput = plugin.runCommands(cmd, {}); - if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput); - } - +Console.prototype.processEmbarkCmd = function(cmd) { if (cmd === 'help') { var helpText = [ 'Welcome to Embark ' + this.version, @@ -31,10 +23,26 @@ Console.prototype.executeCmd = function(cmd, callback) { '', 'The web3 object and the interfaces for the deployed contracts and their methods are also available' ]; - return callback(helpText.join('\n')); + return helpText.join('\n'); } else if (cmd === 'quit') { utils.exit(); } + return false; +}; + +Console.prototype.executeCmd = function(cmd, callback) { + var plugin, pluginOutput; + var plugins = this.plugins.getPluginsFor('console'); + for (var i = 0; i < plugins.length; i++) { + plugin = plugins[i]; + pluginOutput = plugin.runCommands(cmd, {}); + if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput); + } + + var output = this.processEmbarkCmd(cmd); + if (output) { + return callback(output); + } try { var result = RunCode.doEval(cmd);