[Groonga-commit] droonga/droonga-client-ruby at dcaa655 [master] Add a command line utility to send "system.status" command easily

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Apr 15 15:37:06 JST 2015


YUKI Hiroshi	2015-04-15 15:37:06 +0900 (Wed, 15 Apr 2015)

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

  Message:
    Add a command line utility to send "system.status" command easily

  Added files:
    bin/droonga-system-status
    lib/droonga/command/base.rb
  Modified files:
    droonga-client.gemspec

  Added: bin/droonga-system-status (+34 -0) 100755
===================================================================
--- /dev/null
+++ bin/droonga-system-status    2015-04-15 15:37:06 +0900 (570f0d2)
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+#
+# Copyright (C) 2015 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "droonga/command/base"
+
+module Droonga
+  module Command
+    class SystemStatus < Base
+      def run
+        parse_options
+        response = client.request("dataset" => @options[:dataset],
+                                  "type"    => "system.status")
+        puts response["body"]
+        exit(true)
+      end
+    end
+  end
+end
+
+Droonga::Command::SystemStatus.new.run

  Modified: droonga-client.gemspec (+1 -0)
===================================================================
--- droonga-client.gemspec    2015-04-15 15:30:27 +0900 (be5f1d2)
+++ droonga-client.gemspec    2015-04-15 15:37:06 +0900 (f61017c)
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
   spec.add_runtime_dependency "rack"
   spec.add_runtime_dependency "yajl-ruby"
   spec.add_runtime_dependency "droonga-message-pack-packer"
+  spec.add_runtime_dependency "slop"
 
   spec.add_development_dependency "bundler", "~> 1.3"
   spec.add_development_dependency "rake"

  Added: lib/droonga/command/base.rb (+67 -0) 100755
===================================================================
--- /dev/null
+++ lib/droonga/command/base.rb    2015-04-15 15:37:06 +0900 (0ec8aee)
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+#
+# Copyright (C) 2015 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "slop"
+
+require "droonga/client"
+
+module Droonga
+  module Command
+    class Base
+      private
+      def parse_options(&block)
+        options = Slop.parse(:help => true) do |option|
+          yield(option) if block_given?
+
+          option.separator("Connections:")
+          option.on(:host=,
+                    "Host name of the engine node."
+                    :default => Client::DEFAULT_HOST)
+          option.on(:port=,
+                    "Port number to communicate with the engine.",
+                    :as => Integer,
+                    :default => Client::DEFAULT_PORT)
+          option.on(:tag=,
+                    "Tag name to communicate with the engine.",
+                    :default => Client::DEFAULT_TAG)
+          option.on(:dataset=,
+                    "Dataset name for the sending message.",
+                    :default => Client::DEFAULT_DATASET)
+          option.on("receiver-host=",
+                    "Host name of this host.",
+                    :default => Client::DEFAULT_HOST)
+        end
+        @options = options
+      rescue Slop::MissingOptionError => error
+        $stderr.puts(error)
+        exit(false)
+      end
+
+      def client
+        options = {
+          :host          => @options[:host],
+          :port          => @options[:port],
+          :tag           => @options[:tag],
+          :protocol      => :droonga,
+          :receiver_host => @options["receiver-host"],
+          :receiver_port => 0,
+        }
+        @client ||= Droonga::Client.new(options)
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Descargar 



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