YUKI Hiroshi
null+****@clear*****
Thu Dec 6 12:37:33 JST 2012
YUKI Hiroshi 2012-12-06 12:37:33 +0900 (Thu, 06 Dec 2012) New Revision: 928b00f68ecf8a75402e577b389cee7db1441f79 https://github.com/groonga/gcs/commit/928b00f68ecf8a75402e577b389cee7db1441f79 Log: Accept multiple field options by gcs-configure-fields Modified files: bin/gcs-configure-fields bin/gcs-import-examples lib/client.js lib/command-line.js Modified: bin/gcs-configure-fields (+40 -21) =================================================================== --- bin/gcs-configure-fields 2012-12-05 19:02:39 +0900 (ca5a19f) +++ bin/gcs-configure-fields 2012-12-06 12:37:33 +0900 (4bc9356) @@ -19,7 +19,9 @@ commandLine 'result, noresult. Text and literal fields cannot have both the ' + 'facet and result options enabled. By default, text and uint ' + 'fields are always searchable and uint fields are always ' + - 'facet-enabled.', + 'facet-enabled. (Note: If you want to specify multiple options in ' + + 'a time, do "--option option1 --opton option2" or "--option option1 ' + + 'option2".', String) .option('-d, --domain-name <domain name>', 'The name of the domain that you are configuring. Required.', @@ -38,9 +40,22 @@ var fieldName = commandLine.options.name; if (!fieldName) client.raiseFatalError('You must specify the field name.'); -var option = commandLine.options.option; -if (typeof option != 'string') - option = null; +function getFieldOptions() { + var args = client.rawArgs; + var index = args.indexOf('--option'); + if (index < 0) + return []; + + var options = []; + args.slice(index + 1).some(function(arg) { + if (arg == '--option') return false; + if (arg.indexOf('--') == 0) return true; + options.push(arg); + }); + return options; +} + +var fieldOptions = getFieldOptions(); function doDelete(field) { function sendDeleteRequest() { @@ -85,8 +100,6 @@ client.getIndexFieldStatus(fieldName, function(error, field) { if (!field) { if (!type) client.raiseFatalError('You must specify the field type.'); - } else if (!option) { - client.raiseFatalError('You must specify the configuring option.'); } switch (type) { @@ -106,32 +119,38 @@ client.getIndexFieldStatus(fieldName, function(error, field) { } }; - if (option) { + if (fieldOptions.length) { var options = {}; - switch (option) { - case 'search': options.SearchEnabled = 'true'; break; - case 'nosearch': options.SearchEnabled = 'false'; break; - case 'facet': options.FacetEnabled = 'true'; break; - case 'nofacet': options.FacetEnabled = 'false'; break; - case 'result': options.ResultEnabled = 'true'; break; - case 'noresult': options.ResultEnabled = 'false'; break; - default: - client.raiseFatalError('invalid field option ' + option); - } + fieldOptions.forEach(function(option) { + switch (option) { + case 'search': options.SearchEnabled = 'true'; break; + case 'nosearch': options.SearchEnabled = 'false'; break; + case 'facet': options.FacetEnabled = 'true'; break; + case 'nofacet': options.FacetEnabled = 'false'; break; + case 'result': options.ResultEnabled = 'true'; break; + case 'noresult': options.ResultEnabled = 'false'; break; + default: + client.raiseFatalError('invalid field option ' + option); + } + }); switch (type) { case 'text': - if (option == 'search' || option == 'nosearch') + if (fieldOptions.indexOf('search') > -1 || + fieldOptions.indexOf('nosearch') > -1) client.raiseFatalError('searchable option cannot be configured for the type text.'); params.IndexField.TextOptions = options; break; case 'uint': - if (option == 'facet' || option == 'nofacet') + if (fieldOptions.indexOf('facet') > -1 || + fieldOptions.indexOf('nofacet') > -1) client.raiseFatalError('facet option cannot be configured for the type uint.'); - if (option == 'result' || option == 'noresult') + if (fieldOptions.indexOf('result') > -1 || + fieldOptions.indexOf('noresult') > -1) client.raiseFatalError('returnable option cannot be configured for the type uint.'); - if (option == 'search' || option == 'nosearch') + if (fieldOptions.indexOf('search') > -1 || + fieldOptions.indexOf('nosearch') > -1) client.raiseFatalError('searchable option cannot be configured for the type uint.'); params.IndexField.UIntOptions = options; break; Modified: bin/gcs-import-examples (+5 -6) =================================================================== --- bin/gcs-import-examples 2012-12-05 19:02:39 +0900 (b252ff2) +++ bin/gcs-import-examples 2012-12-06 12:37:33 +0900 (a196beb) @@ -105,20 +105,19 @@ search_endpoint=`$bin_path/gcs-describe-domain --domain-name example "$@" | grep echo "==== Adding index fields" echo "== Creating 'name' field" run $bin_path/gcs-configure-fields --domain-name example --name name --type text --option result "$@" -#run $bin_path/gcs-configure-fields --domain-name example --name name --type text --option facet "$@" +#run $bin_path/gcs-configure-fields --domain-name example --name name --type text --option result --option facet "$@" echo echo "== Creating 'address' field" run $bin_path/gcs-configure-fields --domain-name example --name address --type text --option result "$@" -#run $bin_path/gcs-configure-fields --domain-name example --name address --type text --option facet "$@" +#run $bin_path/gcs-configure-fields --domain-name example --name address --type text --option result --option facet "$@" echo echo "== Creating 'email_address' field" run $bin_path/gcs-configure-fields --domain-name example --name email_address --type text --option result "$@" -#run $bin_path/gcs-configure-fields --domain-name example --name email_address --type text --option facet "$@" +#run $bin_path/gcs-configure-fields --domain-name example --name email_address --type text --option result --option facet "$@" echo echo "== Creating 'products' field" -run $bin_path/gcs-configure-fields --domain-name example --name products --type literal --option search "$@" -run $bin_path/gcs-configure-fields --domain-name example --name products --type literal --option result "$@" -#run $bin_path/gcs-configure-fields --domain-name example --name products --type literal --option facet "$@" +run $bin_path/gcs-configure-fields --domain-name example --name products --type literal --option search --option result "$@" +#run $bin_path/gcs-configure-fields --domain-name example --name products --type literal --option search --option result --option facet "$@" echo echo Modified: lib/client.js (+1 -0) =================================================================== --- lib/client.js 2012-12-05 19:02:39 +0900 (e6e8e90) +++ lib/client.js 2012-12-06 12:37:33 +0900 (5f08aa8) @@ -9,6 +9,7 @@ function sendRawDocumentRequest() { } function Client(options) { + this.rawArgs = options.rawArgs; this.domainName = options.domainName; this.host = options.host; this.port = options.port; Modified: lib/command-line.js (+4 -0) =================================================================== --- lib/command-line.js 2012-12-05 19:02:39 +0900 (56ce6c0) +++ lib/command-line.js 2012-12-06 12:37:33 +0900 (8d6fd03) @@ -75,6 +75,10 @@ CommandLineInterface.prototype = { return this.program; }, + get rawArgs() { + return this.program.rawArgs; + }, + parse: function(asClient) { this.program.version(version); -------------- next part -------------- HTML����������������������������... Download