Add Cylon.repl and Robot#repl methods

Each invokes a Repl with some necessary context
This commit is contained in:
Andrew Stewart 2015-04-25 19:37:26 -07:00
parent b2e8f57d24
commit 2ff7dc0866
2 changed files with 32 additions and 0 deletions

View File

@ -13,6 +13,7 @@ var Async = require("async");
var Logger = require("./logger"),
Robot = require("./robot"),
Config = require("./config"),
Repl = require("./repl"),
Utils = require("./utils"),
_ = require("./utils/helpers");
@ -143,6 +144,20 @@ Cylon.config = function(opts) {
return Config;
};
/**
* Starts a new REPL in the context of the MCP.
*
* @return {void}
*/
Cylon.repl = function repl() {
var repl = new Repl(
{ prompt: "mcp > " },
{ robots: this.robots }
);
repl.start();
}
// Public: Halts the API and the robots
//
// callback - callback to be triggered when Cylon is ready to shutdown

View File

@ -11,6 +11,7 @@
var initializer = require("./initializer"),
Logger = require("./logger"),
Utils = require("./utils"),
Repl = require("./repl"),
Config = require("./config"),
_ = require("./utils/helpers");
@ -421,6 +422,22 @@ Robot.prototype.halt = function(callback) {
this.running = false;
};
/**
* Starts a new REPL in the context of the Robot.
*
* @return {void}
*/
Robot.prototype.repl = function() {
var context = {};
_.extend(context, this.connections);
_.extend(context, this.devices);
var repl = new Repl({ prompt: this.name + " > " }, context);
repl.start();
};
// Public: Returns basic info about the robot as a String
//
// Returns a String