add command handler for console cmd

This commit is contained in:
Iuri Matias 2018-02-27 17:04:41 -05:00
parent 445133cfdf
commit eb6236da65
3 changed files with 16 additions and 1 deletions

View File

@ -28,6 +28,9 @@ class Console {
'The web3 object and the interfaces for the deployed contracts and their methods are also available'
];
return helpText.join('\n');
} else if (cmd === 'test') {
this.events.request("console:command", "help", () => {});
return "test";
} else if (['quit', 'exit', 'sair', 'sortir'].indexOf(cmd) >= 0) {
utils.exit();
}

View File

@ -28,7 +28,7 @@ class Dashboard {
callback();
},
function startMonitor(callback) {
monitor = new Monitor({env: self.env, console: console});
monitor = new Monitor({env: self.env, console: console, events: self.events});
self.logger.logFunction = monitor.logEntry;
self.events.on('contractsState', monitor.setContracts);

View File

@ -7,6 +7,7 @@ class Dashboard {
this.env = options.env;
this.console = options.console;
this.history = new CommandHistory();
this.events = options.events;
this.color = options.color || "green";
this.minimal = options.minimal || false;
@ -355,6 +356,17 @@ class Dashboard {
self.input.focus();
});
// TODO: can put cmd exe code into its own method, then set this handler
// outside this
this.events.setCommandHandler("console:command", (cmd, cb) => {
self.history.addCommand(cmd);
self.logText.log('console> '.bold.green + cmd);
self.console.executeCmd(cmd, function (result) {
self.logText.log(result);
cb(result);
});
});
this.screen.append(this.consoleBox);
}