diff --git a/plugins/pilot/lib/cli.js b/plugins/pilot/lib/cli.js index a747678f..b7bb1419 100644 --- a/plugins/pilot/lib/cli.js +++ b/plugins/pilot/lib/cli.js @@ -97,7 +97,7 @@ oop.inherits(ConversionHint, Hint); * @constructor */ function Argument(text, start, end, priorSpace) { - this.text = text; + this.setText(text); this.start = start; this.end = end; this.priorSpace = priorSpace; @@ -114,26 +114,55 @@ Argument.prototype = { }, setText: function(text) { + if (text == null) { + throw new Error('Illegal text for Argument: ' + text); + } this.text = text; } }; /** * Merge an array of arguments into a single argument. */ -Argument.mergeAll = function(argArray) { +Argument.merge = function(argArray, start, end) { + start = (start === undefined) ? 0 : start; + end = (end === undefined) ? argArray.length : end; + var joined; - argArray.forEach(function(arg) { + for (var i = start; i < end; i++) { + var arg = argArray[i]; if (!joined) { joined = arg; } else { joined = joined.merge(arg); } - }); + } return joined; }; +/** + * CLI / UI Interface + * The Cli interacts with the UI via an instance of CliUi. + * This implementation is designed as a template rather than to be used. + * It is expected that we will have a number of implementations of this: + * - A firebug/webkit inspector cli shim + * - A simple input[type=text] version + * - A possible Cloud9 UI version + * - A possible Skywriter UI version + * This class will probably need refactoring as time goes on. + * + * TODO: Who should own the Requisition? + */ +function CliUi() { +} +CliUi.prototype = { + getSelection: function() {}, + setHints: function() {}, + setRequisition: function() {} +}; + + /** * An object used during command line parsing to hold the various intermediate * data steps. @@ -143,7 +172,7 @@ Argument.mergeAll = function(argArray) { *

The other output value is input.requisition which gives access to an * args object for use in executing the final command. * - * The majority of the functions in this class are called in sequence by the + *

The majority of the functions in this class are called in sequence by the * constructor. Their task is to add to hints fill out the requisition. *

The general sequence is: