refactor: extract method for cmd interpreter

This commit is contained in:
Iuri Matias 2017-03-02 07:44:24 -05:00
parent 11eca918a1
commit 4c5cb95209

View File

@ -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);