Bug 771992 - GCLI cookie command completion wonky in xmas tree case; r=dcamp

This commit is contained in:
Joe Walker 2012-07-11 18:21:09 +01:00
parent ac142b1a94
commit 84836f9c94
2 changed files with 107 additions and 16 deletions

View File

@ -5292,14 +5292,14 @@ exports.CommandAssignment = CommandAssignment;
/**
* Special assignment used when ignoring parameters that don't have a home
*/
function UnassignedAssignment(requisition, arg, isIncompleteName) {
function UnassignedAssignment(requisition, arg) {
this.param = new canon.Parameter({
name: '__unassigned',
description: l10n.lookup('cliOptions'),
type: {
name: 'param',
requisition: requisition,
isIncompleteName: isIncompleteName
isIncompleteName: (arg.text.charAt(0) === '-')
},
});
this.paramIndex = -1;
@ -5538,8 +5538,15 @@ Requisition.prototype.cloneAssignments = function() {
Requisition.prototype.getStatus = function() {
var status = Status.VALID;
if (this._unassigned.length !== 0) {
return Status.ERROR;
var isAllIncomplete = true;
this._unassigned.forEach(function(assignment) {
if (!assignment.param.type.isIncompleteName) {
isAllIncomplete = false;
}
});
status = isAllIncomplete ? Status.INCOMPLETE : Status.ERROR;
}
this.getAssignments(true).forEach(function(assignment) {
var assignStatus = assignment.getStatus();
if (assignStatus > status) {
@ -6358,7 +6365,7 @@ Requisition.prototype._split = function(args) {
*/
Requisition.prototype._addUnassignedArgs = function(args) {
args.forEach(function(arg) {
this._unassigned.push(new UnassignedAssignment(this, arg, false));
this._unassigned.push(new UnassignedAssignment(this, arg));
}.bind(this));
};
@ -6401,7 +6408,7 @@ Requisition.prototype._assign = function(args) {
// Positional arguments can still be specified by name, but if they are
// then we need to ignore them when working them out positionally
var names = this.getParameterNames();
var unassignedParams = this.getParameterNames();
// We collect the arguments used in arrays here before assigning
var arrayArgs = {};
@ -6414,7 +6421,7 @@ Requisition.prototype._assign = function(args) {
while (i < args.length) {
if (assignment.param.isKnownAs(args[i].text)) {
var arg = args.splice(i, 1)[0];
names = names.filter(function(test) {
unassignedParams = unassignedParams.filter(function(test) {
return test !== assignment.param.name;
});
@ -6451,7 +6458,7 @@ Requisition.prototype._assign = function(args) {
}, this);
// What's left are positional parameters assign in order
names.forEach(function(name) {
unassignedParams.forEach(function(name) {
var assignment = this.getAssignment(name);
// If not set positionally, and we can't set it non-positionally,
@ -6485,7 +6492,7 @@ Requisition.prototype._assign = function(args) {
arg.text.charAt(0) === '-';
if (isIncompleteName) {
this._unassigned.push(new UnassignedAssignment(this, arg, true));
this._unassigned.push(new UnassignedAssignment(this, arg));
}
else {
var conversion = assignment.param.type.parse(arg);
@ -7043,6 +7050,10 @@ FocusManager.prototype._checkShow = function() {
* available inputs
*/
FocusManager.prototype._shouldShowTooltip = function() {
if (!this._hasFocus) {
return { visible: false, reason: '!hasFocus' };
}
if (eagerHelper.value === Eagerness.NEVER) {
return { visible: false, reason: 'eagerHelper !== NEVER' };
}
@ -7071,6 +7082,10 @@ FocusManager.prototype._shouldShowTooltip = function() {
* available inputs
*/
FocusManager.prototype._shouldShowOutput = function() {
if (!this._hasFocus) {
return { visible: false, reason: '!hasFocus' };
}
if (this._recentOutput) {
return { visible: true, reason: 'recentOutput' };
}
@ -9727,7 +9742,7 @@ Completer.prototype._getCompleterTemplateData = function() {
// arrowTabText is for when we need to use an -> to show what will be used
var directTabText = '';
var arrowTabText = '';
var current = this.inputter.assignment;
var current = this.requisition.getAssignmentAt(input.cursor.start);
if (input.typed.trim().length !== 0) {
var prediction = current.conversion.getPredictionAt(this.choice);

View File

@ -1063,44 +1063,44 @@ exports.check = function(checks) {
}
if (assignment == null) {
test.ok(false, 'Unknown parameter: ' + paramName);
test.ok(false, 'Unknown arg: ' + paramName);
return;
}
if (check.value) {
test.is(assignment.value,
check.value,
'checkStatus value for ' + paramName);
'arg[\'' + paramName + '\'].value');
}
if (check.name) {
test.is(assignment.value.name,
check.name,
'checkStatus name for ' + paramName);
'arg[\'' + paramName + '\'].name');
}
if (check.type) {
test.is(assignment.arg.type,
check.type,
'checkStatus type for ' + paramName);
'arg[\'' + paramName + '\'].type');
}
if (check.arg) {
test.is(assignment.arg.toString(),
check.arg,
'checkStatus arg for ' + paramName);
'arg[\'' + paramName + '\'].arg');
}
if (check.status) {
test.is(assignment.getStatus().toString(),
check.status,
'checkStatus status for ' + paramName);
'arg[\'' + paramName + '\'].status');
}
if (check.message) {
test.is(assignment.getMessage(),
check.message,
'checkStatus message for ' + paramName);
'arg[\'' + paramName + '\'].message');
}
});
}
@ -1733,6 +1733,7 @@ exports.setup = function() {
canon.addCommand(exports.tselarr);
canon.addCommand(exports.tsm);
canon.addCommand(exports.tsg);
canon.addCommand(exports.tscook);
};
exports.shutdown = function() {
@ -1756,6 +1757,7 @@ exports.shutdown = function() {
canon.removeCommand(exports.tselarr);
canon.removeCommand(exports.tsm);
canon.removeCommand(exports.tsg);
canon.removeCommand(exports.tscook);
types.deregisterType(exports.optionType);
types.deregisterType(exports.optionValue);
@ -1975,6 +1977,46 @@ exports.tsg = {
exec: createExec('tsg')
};
exports.tscook = {
name: 'tscook',
description: 'param group test to catch problems with cookie command',
params: [
{
name: 'key',
type: 'string',
description: 'tscookKeyDesc'
},
{
name: 'value',
type: 'string',
description: 'tscookValueDesc'
},
{
group: 'tscookOptionsDesc',
params: [
{
name: 'path',
type: 'string',
defaultValue: '/',
description: 'tscookPathDesc'
},
{
name: 'domain',
type: 'string',
defaultValue: null,
description: 'tscookDomainDesc'
},
{
name: 'secure',
type: 'boolean',
description: 'tscookSecureDesc'
}
]
}
],
exec: createExec('tscook')
};
});
/*
@ -2885,6 +2927,40 @@ exports.testCompleted = function(options) {
}
});
helpers.setInput('tscook key value --path path --');
helpers.check({
input: 'tscook key value --path path --',
markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVII',
directTabText: 'domain',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
args: {
key: { value: 'key', status: 'VALID' },
value: { value: 'value', status: 'VALID' },
path: { value: 'path', status: 'VALID' },
domain: { value: undefined, status: 'VALID' },
secure: { value: false, status: 'VALID' }
}
});
helpers.setInput('tscook key value --path path --domain domain --');
helpers.check({
input: 'tscook key value --path path --domain domain --',
markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVII',
directTabText: 'secure',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
args: {
key: { value: 'key', status: 'VALID' },
value: { value: 'value', status: 'VALID' },
path: { value: 'path', status: 'VALID' },
domain: { value: 'domain', status: 'VALID' },
secure: { value: false, status: 'VALID' }
}
});
// Expand out to christmas tree command line
};