[Groonga-commit] groonga/gcs [master] Report error when invalid combination of options are specified to gcs-configure-text-options.

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 9日 (木) 15:54:05 JST


SHIMODA Hiroshi	2012-08-09 15:54:05 +0900 (Thu, 09 Aug 2012)

  New Revision: a6451afaae98724997e09817ddd701a8ec8cc31a
  https://github.com/groonga/gcs/commit/a6451afaae98724997e09817ddd701a8ec8cc31a

  Log:
    Report error when invalid combination of options are specified to gcs-configure-text-options.

  Modified files:
    bin/gcs-configure-text-options
    lib/command-line.js

  Modified: bin/gcs-configure-text-options (+23 -0)
===================================================================
--- bin/gcs-configure-text-options    2012-08-09 15:38:58 +0900 (86ca9ff)
+++ bin/gcs-configure-text-options    2012-08-09 15:54:05 +0900 (4314440)
@@ -47,6 +47,29 @@ function strip(string) {
   return string.replace(/^\s+|\s+$/g, '');
 }
 
+var printOptions = ['printStems', 'printStopwords', 'printSynonyms'];
+var loadOptions = ['stems', 'stopwords', 'synonyms'];
+
+if (commandLine.hasTooManyExclusiveOptions(printOptions)) {
+  console.log('Too many options. ' +
+              'You must specify just one option from ' +
+              '--print-stems, --print-stopwords, or --print-synonyms.');
+  process.exit(1);
+  return;
+}
+
+if (printOptions.some(function(option) {
+      return commandLine.options[option];
+    }) &&
+    loadOptions.some(function(option) {
+      return commandLine.options[option];
+    })) {
+  console.log('Too many options. ' +
+              'You cannot do print and load on the same time.');
+  process.exit(1);
+  return;
+}
+
 if (commandLine.options.printStems) {
 } else if (commandLine.options.printStopwords) {
 } else if (commandLine.options.printSynonyms) {

  Modified: lib/command-line.js (+7 -0)
===================================================================
--- lib/command-line.js    2012-08-09 15:38:58 +0900 (1b21f2b)
+++ lib/command-line.js    2012-08-09 15:54:05 +0900 (bbf166b)
@@ -85,6 +85,13 @@ CommandLineInterface.prototype = {
     }
     return this;
   },
+
+  hasTooManyExclusiveOptions: function(options) {
+    var havingOptions = options.map(function(option) {
+          return this.option[option] ? '*' : '' ;
+        }, this);
+    return havingOptions.join('').length > 1;
+  }
 };
 exports.CommandLineInterface = CommandLineInterface;
 
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index