Kouhei Sutou
null+****@clear*****
Fri Oct 27 17:07:31 JST 2017
Kouhei Sutou 2017-10-27 17:07:31 +0900 (Fri, 27 Oct 2017) New Revision: f7ca95e6478d77f5a88e393cd1d0761ee98baabb https://github.com/ranguba/groonga-client/commit/f7ca95e6478d77f5a88e393cd1d0761ee98baabb Message: Remove "check" and "index" from option names Because command line name includes them. Modified files: lib/groonga/client/command-line/groonga-client-index-check.rb test/command-line/test-index-check.rb Modified: lib/groonga/client/command-line/groonga-client-index-check.rb (+29 -28) =================================================================== --- lib/groonga/client/command-line/groonga-client-index-check.rb 2017-10-27 16:41:12 +0900 (c6e93de) +++ lib/groonga/client/command-line/groonga-client-index-check.rb 2017-10-27 17:07:31 +0900 (1e2daaa) @@ -28,24 +28,24 @@ module Groonga @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****@metho*****? + @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 @@ -57,19 +57,23 @@ module Groonga 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:") @@ -97,20 +101,17 @@ module Groonga 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 @@ -187,7 +188,7 @@ module Groonga 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"]) @@ -251,7 +252,7 @@ module Groonga 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"] Modified: test/command-line/test-index-check.rb (+4 -4) =================================================================== --- test/command-line/test-index-check.rb 2017-10-27 16:41:12 +0900 (f7bcf92) +++ test/command-line/test-index-check.rb 2017-10-27 17:07:31 +0900 (da844f7) @@ -86,7 +86,7 @@ class TestCommandLineIndexCheck < Test::Unit::TestCase 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 @@ -104,11 +104,11 @@ index column:<Terms.memos_content> is 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 @@ -132,7 +132,7 @@ check 3 tokens against <Terms.memos_content>. CLIENT_OUTPUT assert_equal([true, expected, ""], - run_client_index_check("--check-index-integrity", + run_client_index_check("--method=content", "Terms.memos_content")) end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171027/2296bfde/attachment-0001.htm