YUKI Hiroshi
null+****@clear*****
Mon Oct 15 18:38:21 JST 2012
YUKI Hiroshi 2012-10-15 18:38:21 +0900 (Mon, 15 Oct 2012) New Revision: 8ff6f2b4128ca9404c10672e644bfe630dcf6ff5 https://github.com/groonga/gcs/commit/8ff6f2b4128ca9404c10672e644bfe630dcf6ff5 Log: Make gcs-configure-defaualt-search-field based on HTTP APIs Modified files: bin/gcs-configure-default-search-field lib/command-line.js Modified: bin/gcs-configure-default-search-field (+37 -23) =================================================================== --- bin/gcs-configure-default-search-field 2012-10-15 18:11:16 +0900 (42958a0) +++ bin/gcs-configure-default-search-field 2012-10-15 18:38:21 +0900 (b301bcb) @@ -2,7 +2,6 @@ var CLI = require(__dirname + '/../lib/command-line').CommandLineInterface; var commandLine = new CLI(); -var fs = require('fs'); commandLine .option('-d, --domain-name <domain name>', @@ -15,28 +14,43 @@ commandLine .parse(); commandLine.assertHaveDomainName(); -commandLine.assertDomainExists(); -var field; -if (commandLine.hasOption('name') && commandLine.options.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.'); +var domainName = commandLine.domainName; +var fieldName = commandLine.hasOption('name') && commandLine.options.name; +commandLine.assertDomainExistsHTTP(function() { + if (fieldName) { + commandLine.getIndexFieldStatus(domainName, fieldName, function(error, field) { + if (field) { + console.log('Setting "%s" as the default search field of "%s"...', + fieldName, + domainName); + commandLine.configurationAPI.UpdateDefaultSearchField( + { DefaultSearchField: fieldName }, + function(error, result) { + if (error) + commandLine.raiseFatalError(error); + console.log('Done.'); + process.exit(0); + } + ); + } else { + console.log('"%s" is not a field of "%s".', + fieldName, + domainName); + process.exit(1); + } + }); } else { - console.log('"%s" is not a field of "%s".', - field.name, - commandLine.domain.name); - return process.exit(1); + console.log('Resetting the default search field of "%s"...', + domainName); + commandLine.configurationAPI.UpdateDefaultSearchField( + { DefaultSearchField: '' }, + function(error, result) { + if (error) + commandLine.raiseFatalError(error); + console.log('Done.'); + process.exit(0); + } + ); } -} else { - console.log('Resetting the default search field of "%s"...', - commandLine.domain.name); - commandLine.domain.defaultSearchField = null; - console.log('Done.'); -} +}); Modified: lib/command-line.js (+27 -0) =================================================================== --- lib/command-line.js 2012-10-15 18:11:16 +0900 (7ea38c0) +++ lib/command-line.js 2012-10-15 18:38:21 +0900 (6356a0d) @@ -175,6 +175,33 @@ CommandLineInterface.prototype = { } }, + getIndexFieldStatus: function(domainName, indexFieldName, callback) { + var self = this; + this.configurationAPI.DescribeIndexFields( + { + DomainName: domainName, + 'FieldNames.member.1': indexFieldName + }, + function(error, response) { + if (error) + self.raiseFatalError(error); + + var indexFields = response.Body + .DescribeIndexFieldsResponse + .DescribeIndexFieldsResult + .IndexFields + .member; + indexFields = !indexFields ? [] : + !Array.isArray(indexFields) ? [indexFields] : + indexFields; + if (indexFields.length && indexFields[0]) + callback(null, indexFields[0]); + else + callback(indexFieldName + ' does not exist.', null); + } + ); + }, + getIndexFieldStatuses: function(domainName, callback) { var self = this; this.configurationAPI.DescribeIndexFields( -------------- next part -------------- HTML����������������������������...Download