Kouhei Sutou
null+****@clear*****
Fri Jul 5 18:50:10 JST 2013
Kouhei Sutou 2013-07-05 18:50:10 +0900 (Fri, 05 Jul 2013) New Revision: 10d3c5578f7ae7415a8fa2fce5c882b560937e21 https://github.com/groonga/groonga-query-log/commit/10d3c5578f7ae7415a8fa2fce5c882b560937e21 Message: replayer: extract command line related features as other class Added files: lib/groonga/query-log/command/replay.rb Modified files: bin/groonga-query-log-replay lib/groonga/query-log/replayer.rb Modified: bin/groonga-query-log-replay (+4 -4) =================================================================== --- bin/groonga-query-log-replay 2013-07-05 18:39:28 +0900 (1d80b98) +++ bin/groonga-query-log-replay 2013-07-05 18:50:10 +0900 (18baf07) @@ -17,10 +17,10 @@ # 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 "groonga/query-log" +require "groonga/query-log/command/replay" Thread.abort_on_exception = true -replayer = Groonga::QueryLog::Replayer.new -replayer.parse_command_line_options(ARGV) -replayer.replay(ARGF) +replay_command = Groonga::QueryLog::Command::Replay.new +replay_command.parse_command_line_options(ARGV) +replay_command.run(ARGF) Added: lib/groonga/query-log/command/replay.rb (+95 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga/query-log/command/replay.rb 2013-07-05 18:50:10 +0900 (03d2390) @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# 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 "optparse" + +require "groonga/query-log/replayer" + +module Groonga + module QueryLog + module Command + class Replay + def initialize + @options = Replayer::Options.new + end + + def parse_command_line_options(arguments) + create_parser.parse!(arguments) + end + + def run(input) + replayer = Replayer.new(@options) + replayer.replay(input) + end + + private + def create_parser + parser = OptionParser.new + parser.banner += " QUERY_LOG" + + parser.separator("") + parser.separator("Options:") + + parser.on("--host=HOST", + "Host name or IP address of groonga server", + "[#{@options.host}]") do |host| + @options.host = host + end + + parser.on("--port=PORT", Integer, + "Port number of groonga server", + "[#{@options.port}]") do |port| + @options.port = port + end + + available_protocols = [:gqtp, :http] + available_protocols_label = "[#{available_protocols.join(', ')}]" + parser.on("--protocol=PROTOCOL", available_protocols, + "Protocol of groonga server", + available_protocols_label) do |protocol| + @options.protocol = protocol + end + + parser.on("--n-clients=N", Integer, + "The max number of concurrency", + "[#{@options.n_clients}]") do |n_clients| + @options.n_cilents = n_clients + end + + parser.on("--disable-cache", + "Add 'cache=no' parameter to request", + "[#{@options.disable_cache?}]") do + @options.disable_cache = true + end + + parser.on("--output-requests=PATH", + "Output requests to PATH", + "[not output]") do |path| + @options.requests_path = path + end + + parser.on("--output-responses=PATH", + "Output responses to PATH", + "[not output]") do |path| + @options.responses_path = path + end + end + end + end + end +end Modified: lib/groonga/query-log/replayer.rb (+0 -62) =================================================================== --- lib/groonga/query-log/replayer.rb 2013-07-05 18:39:28 +0900 (a5727b6) +++ lib/groonga/query-log/replayer.rb 2013-07-05 18:50:10 +0900 (187acff) @@ -17,7 +17,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require "thread" -require "optparse" require "groonga/client" @@ -32,10 +31,6 @@ module Groonga @options = options end - def parse_command_line_options(arguments) - @options.parse(arguments) - end - def replay(input) producer = run_producer(input) consumers = run_consumers @@ -132,10 +127,6 @@ module Groonga @responses_path = nil end - def parse(arguments) - create_parser.parse!(arguments) - end - def create_client(&block) Groonga::Client.open(:host => @host, :port => @port, @@ -162,59 +153,6 @@ module Groonga def disable_cache? @disable_cache end - - private - def create_parser - parser = OptionParser.new - parser.banner += " QUERY_LOG" - - parser.separator("") - parser.separator("Options:") - - parser.on("--host=HOST", - "Host name or IP address of groonga server", - "[#{@host}]") do |host| - @host = host - end - - parser.on("--port=PORT", Integer, - "Port number of groonga server", - "[#{@port}]") do |port| - @port = port - end - - available_protocols = [:gqtp, :http] - available_protocols_label = "[#{available_protocols.join(', ')}]" - parser.on("--protocol=PROTOCOL", available_protocols, - "Protocol of groonga server", - available_protocols_label) do |protocol| - @protocol = protocol - end - - parser.on("--n-clients=N", Integer, - "The max number of concurrency", - "[#{@n_clients}]") do |n_clients| - @n_cilents = n_clients - end - - parser.on("--disable-cache", - "Add 'cache=no' parameter to request", - "[#{@disable_cache}]") do - @disable_cache = true - end - - parser.on("--output-requests=PATH", - "Output requests to PATH", - "[not output]") do |path| - @requests_path = path - end - - parser.on("--output-responses=PATH", - "Output responses to PATH", - "[not output]") do |path| - @responses_path = path - end - end end end end -------------- next part -------------- HTML����������������������������...Download