From 2ff7dc086658c5c7d3b3e4a0f95a0f3b2d2f8a1b Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Sat, 25 Apr 2015 19:37:26 -0700 Subject: [PATCH] Add Cylon.repl and Robot#repl methods Each invokes a Repl with some necessary context --- lib/cylon.js | 15 +++++++++++++++ lib/robot.js | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/cylon.js b/lib/cylon.js index 4757fc0..5e59662 100644 --- a/lib/cylon.js +++ b/lib/cylon.js @@ -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 diff --git a/lib/robot.js b/lib/robot.js index 30dcda2..9141a19 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -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