Add Cylon.repl and Robot#repl methods
Each invokes a Repl with some necessary context
This commit is contained in:
parent
b2e8f57d24
commit
2ff7dc0866
15
lib/cylon.js
15
lib/cylon.js
|
@ -13,6 +13,7 @@ var Async = require("async");
|
||||||
var Logger = require("./logger"),
|
var Logger = require("./logger"),
|
||||||
Robot = require("./robot"),
|
Robot = require("./robot"),
|
||||||
Config = require("./config"),
|
Config = require("./config"),
|
||||||
|
Repl = require("./repl"),
|
||||||
Utils = require("./utils"),
|
Utils = require("./utils"),
|
||||||
_ = require("./utils/helpers");
|
_ = require("./utils/helpers");
|
||||||
|
|
||||||
|
@ -143,6 +144,20 @@ Cylon.config = function(opts) {
|
||||||
return Config;
|
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
|
// Public: Halts the API and the robots
|
||||||
//
|
//
|
||||||
// callback - callback to be triggered when Cylon is ready to shutdown
|
// callback - callback to be triggered when Cylon is ready to shutdown
|
||||||
|
|
17
lib/robot.js
17
lib/robot.js
|
@ -11,6 +11,7 @@
|
||||||
var initializer = require("./initializer"),
|
var initializer = require("./initializer"),
|
||||||
Logger = require("./logger"),
|
Logger = require("./logger"),
|
||||||
Utils = require("./utils"),
|
Utils = require("./utils"),
|
||||||
|
Repl = require("./repl"),
|
||||||
Config = require("./config"),
|
Config = require("./config"),
|
||||||
_ = require("./utils/helpers");
|
_ = require("./utils/helpers");
|
||||||
|
|
||||||
|
@ -421,6 +422,22 @@ Robot.prototype.halt = function(callback) {
|
||||||
this.running = false;
|
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
|
// Public: Returns basic info about the robot as a String
|
||||||
//
|
//
|
||||||
// Returns a String
|
// Returns a String
|
||||||
|
|
Loading…
Reference in New Issue