Navigation Menu

Skip to content

Commit

Permalink
Exit in bin/ scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 2, 2014
1 parent 0fb3a33 commit 4e7a2dc
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 46 deletions.
8 changes: 2 additions & 6 deletions bin/groonga-query-log-analyze
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
# Copyright (C) 2014 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
Expand All @@ -20,9 +21,4 @@
require "groonga/query-log"

analyzer = Groonga::QueryLog::Analyzer.new
begin
analyzer.run(*ARGV)
rescue Groonga::QueryLog::Analyzer::Error
$stderr.puts($!.message)
exit(false)
end
exit(analyzer.run(ARGV))
4 changes: 2 additions & 2 deletions bin/groonga-query-log-detect-memory-leak
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2013-2014 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
Expand All @@ -20,4 +20,4 @@
require "groonga/query-log/command/detect-memory-leak"

detect_memory_leak_command = Groonga::QueryLog::Command::DetectMemoryLeak.new
detect_memory_leak_command.run(*ARGV)
exit(detect_memory_leak_command.run(ARGV))
9 changes: 2 additions & 7 deletions bin/groonga-query-log-extract
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2011-2014 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
#
# This library is free software; you can redistribute it and/or
Expand All @@ -20,9 +20,4 @@
require "groonga/query-log/extractor"

extracter = Groonga::QueryLog::Extractor.new
begin
extracter.run(*ARGV)
rescue Groonga::QueryLog::Extractor::Error
$stderr.puts($!.message)
exit(false)
end
exit(extracter.run(*ARGV))
4 changes: 2 additions & 2 deletions bin/groonga-query-log-replay
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2013-2014 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
Expand All @@ -20,4 +20,4 @@
require "groonga/query-log/command/replay"

replay_command = Groonga::QueryLog::Command::Replay.new
replay_command.run(*ARGV)
exit(replay_command.run(ARGV))
2 changes: 1 addition & 1 deletion bin/groonga-query-log-run-regression-test
Expand Up @@ -20,4 +20,4 @@
require "groonga/query-log/command/run-regression-test"

command = Groonga::QueryLog::Command::RunRegressionTest.new
command.run(*ARGV)
exit(command.run(ARGV))
4 changes: 2 additions & 2 deletions bin/groonga-query-log-verify-server
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2013-2014 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
Expand All @@ -20,4 +20,4 @@
require "groonga/query-log/command/verify-server"

verify_server_command = Groonga::QueryLog::Command::VerifyServer.new
verify_server_command.run(*ARGV)
exit(verify_server_command.run(ARGV))
14 changes: 8 additions & 6 deletions lib/groonga/query-log/analyzer.rb
Expand Up @@ -57,7 +57,7 @@ def initialize
# @param [Array<String>] arguments arguments for
# groonga-query-log-analyze. Please execute
# "groonga-query-log-analyze --help" or see #setup_options.
def run(*arguments)
def run(arguments)
log_paths = @option_parser.parse!(arguments)

stream = @options[:stream]
Expand Down Expand Up @@ -89,13 +89,15 @@ def run(*arguments)

if stream
streamer.finish
return
else
statistics.replace(full_statistics) unless dynamic_sort

reporter = create_reporter(statistics)
reporter.apply_options(@options)
reporter.report
end
statistics.replace(full_statistics) unless dynamic_sort

reporter = create_reporter(statistics)
reporter.apply_options(@options)
reporter.report
true
end

private
Expand Down
7 changes: 4 additions & 3 deletions lib/groonga/query-log/command/detect-memory-leak.rb
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2013-2014 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
Expand Down Expand Up @@ -28,14 +28,15 @@ def initialize
@options = MemoryLeakDetector::Options.new
end

def run(*command_line)
input_paths = create_parser.parse(*command_line)
def run(command_line)
input_paths = create_parser.parse(command_line)
detector = MemoryLeakDetector.new(@options)
input_paths.each do |input_path|
File.open(input_path) do |input|
detector.detect(input)
end
end
true
end

private
Expand Down
7 changes: 4 additions & 3 deletions lib/groonga/query-log/command/replay.rb
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2013-2014 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
Expand Down Expand Up @@ -28,14 +28,15 @@ def initialize
@options = Replayer::Options.new
end

def run(*command_line)
input_paths = create_parser.parse(*command_line)
def run(command_line)
input_paths = create_parser.parse(command_line)
replayer = Replayer.new(@options)
input_paths.each do |input_path|
File.open(input_path) do |input|
replayer.replay(input)
end
end
true
end

private
Expand Down
12 changes: 7 additions & 5 deletions lib/groonga/query-log/command/run-regression-test.rb
Expand Up @@ -44,7 +44,7 @@ def initialize
@skip_finished_queries = false
end

def run(*command_line)
def run(command_line)
option_parser = create_option_parser
begin
option_parser.parse!(command_line)
Expand Down Expand Up @@ -299,14 +299,16 @@ def run
end
end

old_thread.join
new_thread.join
old_thread_success = old_thread.value
new_thread_success = new_thread.value

old_thread_success and new_thread_success
end

private
def run_test
@n_ready_waits -= 1
return unless @n_ready_waits.zero?
return true unless @n_ready_waits.zero?

@clone_pids.each do |pid|
Process.waitpid(pid)
Expand Down Expand Up @@ -358,7 +360,7 @@ def verify_server(test_log_path, query_log_path)
query_log_path.to_s,
]
verify_serer = VerifyServer.new
verify_serer.run(*command_line)
verify_serer.run(command_line)
end

def query_log_paths
Expand Down
7 changes: 4 additions & 3 deletions lib/groonga/query-log/command/verify-server.rb
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2013-2014 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
Expand Down Expand Up @@ -28,8 +28,8 @@ def initialize
@options = ServerVerifier::Options.new
end

def run(*command_line)
input_paths = create_parser.parse(*command_line)
def run(command_line)
input_paths = create_parser.parse(command_line)
verifier = ServerVerifier.new(@options)
if input_paths.empty?
verifier.verify($stdin)
Expand All @@ -40,6 +40,7 @@ def run(*command_line)
end
end
end
true
end

private
Expand Down
13 changes: 7 additions & 6 deletions lib/groonga/query-log/extractor.rb
Expand Up @@ -31,9 +31,6 @@ class Extractor
class Error < StandardError
end

class NoInputError < Error
end

attr_accessor :options
attr_reader :option_parser

Expand All @@ -58,16 +55,18 @@ def initialize
# @param [Array<String>] arguments arguments for
# groonga-query-log-extract. Please execute
# "groonga-query-log-extract --help" or see #setup_options.
def run(*arguments)
def run(arguments)
begin
log_paths = @option_parser.parse!(arguments)
rescue OptionParser::ParseError
raise(ArgumentError, $!.message)
$stderr.puts($!.message)
return false
end

if log_paths.empty?
unless log_via_stdin?
raise(NoInputError, "Error: Please specify input log files.")
$stderr.puts("Error: Please specify input log files.")
return false
end
log = $stdin
else
Expand All @@ -81,6 +80,8 @@ def run(*arguments)
else
extract(log, $stdout)
end

true
end

private
Expand Down

0 comments on commit 4e7a2dc

Please sign in to comment.