Use console and override evaluator

This commit is contained in:
Anthony Laibe 2018-07-26 16:00:25 +01:00 committed by Pascal Precht
parent 6755b96aff
commit f7c280b693
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 16 additions and 14 deletions

View File

@ -1,34 +1,36 @@
const repl = require("repl");
const Console = require('./console.js');
class REPL {
constructor(options) {
this.env = options.env;
this.plugins = options.plugins;
this.events = options.events;
this.console = new Console({
events: this.events,
plugins: this.plugins,
version: options.version
});
}
enhancedEval(cmd, context, filename, callback) {
this.console.executeCmd(cmd.trim(), (result) => {
callback(null, result);
});
}
start(done) {
this.replServer = repl.start({
prompt: "Embark (" + this.env + ") > ",
useGlobal: true
useGlobal: true,
eval: this.enhancedEval.bind(this)
});
this.replServer.on("exit", () => {
process.exit();
});
let self = this;
this.replServer.defineCommand('profile', {
help: 'Profile a contract',
action(contract) {
this.clearBufferedCommand();
let pluginCmds = self.plugins.getPluginsProperty('console', 'console');
for (let pluginCmd of pluginCmds) {
pluginCmd.call(self, `profile ${contract}`, {});
}
this.displayPrompt();
}
});
done();
}