Use console and override evaluator
This commit is contained in:
parent
da85f39424
commit
d5911cb3b7
|
@ -1,34 +1,36 @@
|
||||||
const repl = require("repl");
|
const repl = require("repl");
|
||||||
|
|
||||||
|
const Console = require('./console.js');
|
||||||
|
|
||||||
class REPL {
|
class REPL {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
this.plugins = options.plugins;
|
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) {
|
start(done) {
|
||||||
this.replServer = repl.start({
|
this.replServer = repl.start({
|
||||||
prompt: "Embark (" + this.env + ") > ",
|
prompt: "Embark (" + this.env + ") > ",
|
||||||
useGlobal: true
|
useGlobal: true,
|
||||||
|
eval: this.enhancedEval.bind(this)
|
||||||
});
|
});
|
||||||
|
|
||||||
this.replServer.on("exit", () => {
|
this.replServer.on("exit", () => {
|
||||||
process.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();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -281,7 +281,12 @@ class Embark {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function startREPL(callback) {
|
function startREPL(callback) {
|
||||||
let repl = new REPL({env: engine.env, plugins: engine.plugins});
|
let repl = new REPL({
|
||||||
|
env: engine.env,
|
||||||
|
plugins: engine.plugins,
|
||||||
|
version: engine.version,
|
||||||
|
events: engine.events
|
||||||
|
});
|
||||||
repl.start(callback);
|
repl.start(callback);
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
|
|
Loading…
Reference in New Issue