Navigation Menu

Skip to content

Commit

Permalink
Handle ommited "name" option for gcs-configure-default-search-field c…
Browse files Browse the repository at this point in the history
…orrectly
  • Loading branch information
piroor committed Aug 27, 2012
1 parent b6b9c21 commit 53fb63d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
31 changes: 19 additions & 12 deletions bin/gcs-configure-default-search-field
Expand Up @@ -17,19 +17,26 @@ commandLine
commandLine.assertHaveDomainName();
commandLine.assertDomainExists();

var field = commandLine.domain.getIndexField(commandLine.options.name);
if (field && field.exists()) {
console.log('Setting "%s" as the default search field of "%s"...',
field.name,
commandLine.domain.name);
} else if (commandLine.options.name) {
console.log('"%s" is not a field of "%s".',
field.name,
commandLine.domain.name);
return process.exit(1);
var field;
if (commandLine.hasOption('name'))
field = commandLine.domain.getIndexField(commandLine.options.name);

if (field) {
if (field.exists()) {
console.log('Setting "%s" as the default search field of "%s"...',
field.name,
commandLine.domain.name);
commandLine.domain.defaultSearchField = field;
console.log('Done.');
} else {
console.log('"%s" is not a field of "%s".',
field.name,
commandLine.domain.name);
return process.exit(1);
}
} else {
console.log('Resetting the default search field of "%s"...',
commandLine.domain.name);
commandLine.domain.defaultSearchField = null;
console.log('Done.');
}
commandLine.domain.defaultSearchField = field;
console.log('Done.');
5 changes: 5 additions & 0 deletions lib/command-line.js
Expand Up @@ -95,6 +95,11 @@ CommandLineInterface.prototype = {
return this;
},

hasOption: function(option) {
return this.program.rawArgs.indexOf('--' + option) > -1 ||
this.program.rawArgs.indexOf('-' + option) > -1;
},

hasTooManyExclusiveOptions: function(options) {
var havingOptions = options.map(function(option) {
return this.option[option] ? '*' : '' ;
Expand Down
2 changes: 1 addition & 1 deletion test/gcs-commands.test.js
Expand Up @@ -802,7 +802,7 @@ suite('gcs-configure-default-search-field', function() {
message: result.output.stdout },
{ code: 0,
message: 'Resetting the default search field of ' +
'"companies"...' +
'"companies"...\n' +
'Done.\n' },
result.output.stderr);
assert.isTrue(domain.defaultSearchField === null,
Expand Down

0 comments on commit 53fb63d

Please sign in to comment.