[Groonga-commit] groonga/gcs [master] Handle ommited "name" option for gcs-configure-default-search-field correctly

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Aug 27 17:10:01 JST 2012


YUKI Hiroshi	2012-08-27 17:10:01 +0900 (Mon, 27 Aug 2012)

  New Revision: 53fb63dfbf56b74e41c0214f6cc2ee39f8a028c8
  https://github.com/groonga/gcs/commit/53fb63dfbf56b74e41c0214f6cc2ee39f8a028c8

  Log:
    Handle ommited "name" option for gcs-configure-default-search-field correctly

  Modified files:
    bin/gcs-configure-default-search-field
    lib/command-line.js
    test/gcs-commands.test.js

  Modified: bin/gcs-configure-default-search-field (+19 -12)
===================================================================
--- bin/gcs-configure-default-search-field    2012-08-27 16:42:11 +0900 (556459f)
+++ bin/gcs-configure-default-search-field    2012-08-27 17:10:01 +0900 (38b9e10)
@@ -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.');

  Modified: lib/command-line.js (+5 -0)
===================================================================
--- lib/command-line.js    2012-08-27 16:42:11 +0900 (178b8f8)
+++ lib/command-line.js    2012-08-27 17:10:01 +0900 (367a7ce)
@@ -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] ? '*' : '' ;

  Modified: test/gcs-commands.test.js (+1 -1)
===================================================================
--- test/gcs-commands.test.js    2012-08-27 16:42:11 +0900 (d754d29)
+++ test/gcs-commands.test.js    2012-08-27 17:10:01 +0900 (9c4766e)
@@ -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,
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index