Navigation Menu

Skip to content

Commit

Permalink
Add a command line utility to send "system.status" command easily
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 15, 2015
1 parent 330be84 commit dcaa655
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bin/droonga-system-status
@@ -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
1 change: 1 addition & 0 deletions droonga-client.gemspec
Expand Up @@ -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"
Expand Down
67 changes: 67 additions & 0 deletions lib/droonga/command/base.rb
@@ -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

0 comments on commit dcaa655

Please sign in to comment.