Bug 850929 - GCLI needs a simpler way to mark parameters as being options; r=paul

This commit is contained in:
Joe Walker 2013-03-22 09:37:52 +00:00
parent 40234f7436
commit 79ba59d7e8
5 changed files with 57 additions and 28 deletions

View File

@ -3440,17 +3440,20 @@ function Command(commandSpec) {
// prevents nesting.
paramSpecs.forEach(function(spec) {
if (!spec.group) {
if (usingGroups) {
var param = new Parameter(spec, this, null);
this.params.push(param);
if (!param.isPositionalAllowed) {
this.hasNamedParameters = true;
}
if (usingGroups && param.groupName == null) {
throw new Error('Parameters can\'t come after param groups.' +
' Ignoring ' + this.name + '/' + spec.name);
}
else {
var param = new Parameter(spec, this, null);
this.params.push(param);
if (!param.isPositionalAllowed) {
this.hasNamedParameters = true;
}
if (param.groupName != null) {
usingGroups = true;
}
}
else {
@ -3480,7 +3483,20 @@ function Parameter(paramSpec, command, groupName) {
this.paramSpec = paramSpec;
this.name = this.paramSpec.name;
this.type = this.paramSpec.type;
this.groupName = groupName;
if (this.groupName != null) {
if (this.paramSpec.option != null) {
throw new Error('Can\'t have a "option" property in a nested parameter');
}
}
else {
if (this.paramSpec.option != null) {
this.groupName = this.paramSpec.option === true ?
l10n.lookup('canonDefaultGroupName') :
'' + this.paramSpec.option;
}
}
if (!this.name) {
throw new Error('In ' + this.command.name +
@ -9381,7 +9397,8 @@ var prefShowCmdSpec = {
}
],
exec: function Command_prefShow(args, context) {
return l10n.lookupFormat('prefShowSettingValue', [ args.setting.name, args.setting.value ]);
return l10n.lookupFormat('prefShowSettingValue',
[ args.setting.name, args.setting.value ]);
}
};

View File

@ -199,5 +199,4 @@ exports.testAddRemove3 = function(options) {
canon.onCanonChange.remove(canonChange);
};
// });

View File

@ -35,8 +35,10 @@ function test() {
'use strict';
// var mockCommands = require('gclitest/mockCommands');
var nodetype = require('gcli/types/node');
var canon = require('gcli/canon');
// var assert = require('test/assert');
// var mockCommands = require('gclitest/mockCommands');
// var helpers = require('gclitest/helpers');
@ -71,6 +73,16 @@ var mockDoc = {
}
};
exports.testParamGroup = function(options) {
var tsg = canon.getCommand('tsg');
assert.is(tsg.params[0].groupName, null, 'tsg param 0 group null');
assert.is(tsg.params[1].groupName, 'First', 'tsg param 1 group First');
assert.is(tsg.params[2].groupName, 'First', 'tsg param 2 group First');
assert.is(tsg.params[3].groupName, 'Second', 'tsg param 3 group Second');
assert.is(tsg.params[4].groupName, 'Second', 'tsg param 4 group Second');
};
exports.testWithHelpers = function(options) {
return helpers.audit(options, [
{

View File

@ -370,21 +370,18 @@ mockCommands.tsg = {
]
},
{
group: 'Second',
params: [
{
name: 'txt2',
type: 'string',
defaultValue: 'd',
description: 'txt2 param'
},
{
name: 'num',
type: { name: 'number', min: 40 },
defaultValue: 42,
description: 'num param'
}
]
name: 'txt2',
type: 'string',
defaultValue: 'd',
description: 'txt2 param',
option: 'Second'
},
{
name: 'num',
type: { name: 'number', min: 40 },
defaultValue: 42,
description: 'num param',
option: 'Second'
}
],
exec: createExec('tsg')

View File

@ -15,6 +15,10 @@
# or command parameter when no description has been provided.
canonDescNone=(No description)
# LOCALIZATION NOTE (canonDefaultGroupName): The default name for a group of
# parameters.
canonDefaultGroupName=Options
# LOCALIZATION NOTE (cliEvalJavascript): The special '{' command allows entry
# of JavaScript like traditional developer tool command lines. This describes
# the '{' command.
@ -239,9 +243,9 @@ prefShowSettingDesc=Setting to display
# for help on what it does.
prefShowSettingManual=The name of the setting to display
# LOCALIZATION NOTE (prefShowSettingValue): This is used to show the preference
# name and the associated preference value. %1$S is replaced with the preference
# name and %2$S is replaced with the preference value.
# LOCALIZATION NOTE (prefShowSettingValue): This is used to show the
# preference name and the associated preference value. %1$S is replaced with
# the preference name and %2$S is replaced with the preference value.
prefShowSettingValue=%1$S: %2$S
# LOCALIZATION NOTE (prefSetDesc): A very short description of the 'pref set'