Navigation Menu

Skip to content

Commit

Permalink
Remove "check" and "index" from option names
Browse files Browse the repository at this point in the history
Because command line name includes them.
  • Loading branch information
kou committed Oct 27, 2017
1 parent 4b4c0fa commit f7ca95e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
57 changes: 29 additions & 28 deletions lib/groonga/client/command-line/groonga-client-index-check.rb
Expand Up @@ -28,24 +28,24 @@ def initialize
@protocol = :http
@host = "localhost"
@port = 10041
@check_missing_source = false
@check_index_integrity = false

@available_methods = [:source, :content]
@methods = []
end

def run(argv)
targets = parse_command_line(argv)

if @methods.empty?
@methods = @available_methods
end

Client.open(:url => @url,
:protocol => @protocol,
:host => @host,
:port => @port,
:backend => :synchronous) do |client|
options = {
:check_missing_source => @check_missing_source,
:check_index_integrity => @check_index_integrity,
:targets => targets,
}
checker = Checker.new(client, options)
checker = Checker.new(client, @methods, targets)
checker.check
end
end
Expand All @@ -57,19 +57,23 @@ def parse_command_line(argv)
parser.banner += " [LEXICON1.INDEX1 LEXICON2.INDEX2 ...]"

parser.separator("")
parser.separator("If no indexes are specified, " +
"all indexes are checked.")

parser.separator("Mode:")
parser.separator("")

parser.on("--check-missing-source",
"Check whether there is an index column which lacks index source.",
"(false)") do
@check_missing_source = true
end
parser.separator("Method:")

parser.on("--check-index-integrity",
"Check whether there is a broken index column.",
"(false)") do
@check_index_integrity = true
parser.on("--method=METHOD", @available_methods,
"Specify a method how to check indexes.",
"You can specify this option multiple times",
"to use multiple methods in one execution.",
"All methods are used by default.",
"Available methods:",
" source: Find indexes that don't have source.",
" content: Find indexes that their content is broken.",
"(#{@available_methods.join(", ")})") do |method|
@methods << method
end

parser.separator("Connection:")
Expand Down Expand Up @@ -97,20 +101,17 @@ def parse_command_line(argv)
end

class Checker
def initialize(client, options)
def initialize(client, methods, targets)
@client = client
@options = options
@targets = @options[:targets]
@methods = methods
@targets = targets
end

def check
catch(:fail) do
succeeded = true
if @options[:check_missing_source]
succeeded = false unless check_missing_source
end
if @options[:check_index_integrity]
succeeded = false unless check_index_integrity
@methods.each do |method|
succeeded = false unless __send__("check_#{method}")
end
succeeded
end
Expand Down Expand Up @@ -187,7 +188,7 @@ def missing_source?(column)
column["type"] == "index" and column["source"].empty?
end

def check_missing_source
def check_source
missing_index_names = []
table_list.each do |table|
unless check_target_table?(table["name"])
Expand Down Expand Up @@ -251,7 +252,7 @@ def verify_tokens(table_name, old_column, new_column, tokens)
broken_index_tokens
end

def check_index_integrity
def check_content
table_names = table_list.collect do |table|
if check_target_table?(table["name"])
table["name"]
Expand Down
8 changes: 4 additions & 4 deletions test/command-line/test-index-check.rb
Expand Up @@ -86,7 +86,7 @@ def run_client_index_check(*arguments)
end
end

def test_check_missing_source
def test_source
restore(<<-COMMANDS)
table_create Memos TABLE_HASH_KEY ShortText
column_create Memos content COLUMN_SCALAR Text
Expand All @@ -104,11 +104,11 @@ def test_check_missing_source
CLIENT_OUTPUT

assert_equal([false, expected, ""],
run_client_index_check("--check-missing-source",
run_client_index_check("--method=source",
"Terms.memos_content"))
end

def test_check_index_integrity
def test_content
restore(<<-COMMANDS)
table_create Memos TABLE_HASH_KEY ShortText
column_create Memos content COLUMN_SCALAR Text
Expand All @@ -132,7 +132,7 @@ def test_check_index_integrity
CLIENT_OUTPUT

assert_equal([true, expected, ""],
run_client_index_check("--check-index-integrity",
run_client_index_check("--method=content",
"Terms.memos_content"))

end
Expand Down

0 comments on commit f7ca95e

Please sign in to comment.