From f8af72dd0798040f0888fa4479264c0ccd0f3a95 Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Thu, 2 Dec 2010 12:43:11 +0000 Subject: [PATCH] fix hints, now all cli tests pass --- plugins/pilot/lib/cli.js | 35 +++++++++++++++++++++---------- plugins/pilot/lib/test/testCli.js | 3 +-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/plugins/pilot/lib/cli.js b/plugins/pilot/lib/cli.js index 9d8421ba..a747678f 100644 --- a/plugins/pilot/lib/cli.js +++ b/plugins/pilot/lib/cli.js @@ -44,9 +44,10 @@ var oop = require('pilot/oop').oop; var EventEmitter = require('pilot/event_emitter').EventEmitter; //var keyboard = require('keyboard/keyboard'); -var Status = require('pilot/types').Status; -var canon = require('pilot/canon'); var types = require('pilot/types'); +var Status = require('pilot/types').Status; +var Conversion = require('pilot/types').Conversion; +var canon = require('pilot/canon'); /** @@ -662,7 +663,14 @@ Requisition.prototype = { * Collect the statuses from the Assignments */ getHints: function() { - + var hints = []; + Object.keys(this._assignments).map(function(name) { + var hint = this._assignments[name].getHint(); + if (hint) { + hints.push(hint); + } + }, this); + return hints; }, /** @@ -736,8 +744,7 @@ Assignment.prototype = { this.arg.setText(text); } this.value = value; - this.status = Status.VALID; - this.message = ''; + this.conversion = new Conversion(value, Status.VALID, '', []); //this._dispatchEvent('change', { assignment: this }); }, @@ -750,20 +757,26 @@ Assignment.prototype = { if (this.arg === arg) { return; } - var conversion = this.param.type.parse(arg.text); this.arg = arg; - this.value = conversion.value; - this.status = conversion.status; - this.message = conversion.message; + this.conversion = this.param.type.parse(arg.text); + this.value = this.conversion.value; //this._dispatchEvent('change', { assignment: this }); }, + getHint: function() { + if (this.conversion.status === Status.VALID && + this.conversion.message === '') { + return undefined; + } + + return new ConversionHint(this.conversion, this.arg); + }, + /** * Report on the status of the last parse() conversion. * @see types.Conversion */ - status: undefined, - message: undefined + conversion: undefined }; oop.implement(Assignment, EventEmitter); exports.Assignment = Assignment; diff --git a/plugins/pilot/lib/test/testCli.js b/plugins/pilot/lib/test/testCli.js index 875a8f04..b6d2223b 100644 --- a/plugins/pilot/lib/test/testCli.js +++ b/plugins/pilot/lib/test/testCli.js @@ -169,11 +169,10 @@ exports.testInput = function() { test.verifyEqual('set', input.requisition.command.name); input.parse('set h'); -console.log(input); test.verifyEqual(1, input.hints.length); test.verifyEqual(Status.INCOMPLETE, input.hints[0].status); test.verifyEqual('set', input.requisition.command.name); - test.verifyEqual('h', input.requisition.getAssignment('setting').text); + test.verifyEqual('h', input.requisition.getAssignment('setting').arg.text); test.verifyEqual(undefined, input.requisition.getAssignment('setting').value); return "testInput Completed";