[Groonga-commit] droonga/droonga-client-ruby at 14cf197 [master] Add ability to do dry-run for any command

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri May 29 17:43:06 JST 2015


YUKI Hiroshi	2015-05-29 17:43:06 +0900 (Fri, 29 May 2015)

  New Revision: 14cf1970b0774129dc92cc4d7c11bd081af4d00a
  https://github.com/droonga/droonga-client-ruby/commit/14cf1970b0774129dc92cc4d7c11bd081af4d00a

  Message:
    Add ability to do dry-run for any command

  Modified files:
    lib/droonga/command/base.rb

  Modified: lib/droonga/command/base.rb (+15 -2)
===================================================================
--- lib/droonga/command/base.rb    2015-05-29 17:41:32 +0900 (b183141)
+++ lib/droonga/command/base.rb    2015-05-29 17:43:06 +0900 (fc7bf9e)
@@ -33,6 +33,10 @@ module Droonga
         options = Slop.parse(:help => true) do |option|
           yield(option) if block_given?
 
+          option.on(:"dry-run",
+                    "Only reports messages to be sent to the engine.",
+                    :default => false)
+
           option.separator("Connections:")
           option.on(:host=,
                     "Host name of the engine node.",
@@ -63,12 +67,21 @@ module Droonga
         raise MissingRequiredParameter.new
       end
 
-      def request(message)
+      def request(message, &block)
+        if @options[:"dry-run"]
+          if @options[:pretty]
+            puts(JSON.pretty_generate(message))
+          else
+            puts(JSON.generate(message))
+          end
+          return nil
+        end
+
         response = nil
         open do |client|
           response = client.request(message)
         end
-        response
+        yield response
       end
 
       def send(message)
-------------- next part --------------
HTML����������������������������...
Download 



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