Kouhei Sutou
null+****@clear*****
Fri Dec 12 11:31:15 JST 2014
Kouhei Sutou 2014-12-12 11:31:15 +0900 (Fri, 12 Dec 2014) New Revision: 4a242135d6880666026ecb05fb5808913d75ae59 https://github.com/groonga/groonga-command-parser/commit/4a242135d6880666026ecb05fb5808913d75ae59 Message: Add groonga-command-convert-format "load" command isn't supported. Added files: bin/groonga-command-convert-format lib/groonga/command/parser/command/groonga-command-convert-format.rb Modified files: groonga-command-parser.gemspec lib/groonga/command/parser.rb Added: bin/groonga-command-convert-format (+22 -0) 100755 =================================================================== --- /dev/null +++ bin/groonga-command-convert-format 2014-12-12 11:31:15 +0900 (cc7cd5e) @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby +# +# 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 +# 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 "groonga/command/parser/command/groonga-command-convert-format" + +command = Groonga::Command::Parser::Command::GroongaCommandConvertFormat.new +exit(command.run(ARGV)) Modified: groonga-command-parser.gemspec (+3 -3) =================================================================== --- groonga-command-parser.gemspec 2014-10-02 21:10:21 +0900 (3d4e593) +++ groonga-command-parser.gemspec 2014-12-12 11:31:15 +0900 (0a97286) @@ -44,9 +44,9 @@ Gem::Specification.new do |spec| spec.files += Dir.glob("lib/**/*.rb") spec.files += Dir.glob("doc/text/*") spec.test_files += Dir.glob("test/**/*") - # Dir.chdir("bin") do - # spec.executables = Dir.glob("*") - # end + Dir.chdir("bin") do + spec.executables = Dir.glob("*") + end spec.homepage = "https://github.com/groonga/groonga-command-parser" spec.licenses = ["LGPLv2.1+"] Modified: lib/groonga/command/parser.rb (+2 -2) =================================================================== --- lib/groonga/command/parser.rb 2014-10-02 21:10:21 +0900 (08ee46f) +++ lib/groonga/command/parser.rb 2014-12-12 11:31:15 +0900 (228820c) @@ -369,7 +369,7 @@ module Groonga end name, output_type = name.split(/\./, 2) arguments["output_type"] = output_type if output_type - command_class = Command.find(name) + command_class = ::Groonga::Command.find(name) command = command_class.new(name, arguments) command.original_format = :uri command.path_prefix = prefix @@ -400,7 +400,7 @@ module Groonga ordered_arguments << argument end end - command_class = Command.find(name) + command_class = ::Groonga::Command.find(name) command = command_class.new(name, pair_arguments, ordered_arguments) command.original_format = :command command Added: lib/groonga/command/parser/command/groonga-command-convert-format.rb (+98 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga/command/parser/command/groonga-command-convert-format.rb 2014-12-12 11:31:15 +0900 (6c88299) @@ -0,0 +1,98 @@ +# 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 +# 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/command/parser" + +module Groonga + module Command + class Parser + module Command + class GroongaCommandConvertFormat + def initialize + @format = :command + @uri_prefix = "http://localhost:10041" + end + + def run(argv=ARGV) + begin + parse_options!(argv) + rescue OptionParser::ParseError + puts($!.message) + return false + end + + input_paths = argv + if input_paths.empty? + convert($stdin) + else + input_paths.each do |input_path| + File.open(input_path) do |input| + convert(input) + end + end + end + + true + end + + private + def parse_options!(argv) + option_parser = OptionParser.new + option_parser.banner += " INPUT_PATH1 INPUT_PATH2 ..." + option_parser.version = VERSION + + formats = [:uri, :command] + option_parser.on("--format=FORMAT", formats, + "Convert to FORMAT", + "Available formats #{formats.join(', ')}", + "[#{@format}]") do |format| + @format = format + end + + option_parser.on("--uri-prefix=PREFIX", + "Add PREFIX to URI", + "[#{@uri_prefix}]") do |prefix| + @uri_prefix = prefix + end + + option_parser.parse!(argv) + end + + def convert(input) + parser = Parser.new + parser.on_command do |command| + puts(convert_format(command)) + end + input.each_line do |line| + parser << line + end + end + + def convert_format(command) + case @format + when :uri + "#{@uri_prefix}#{command.to_uri_format}" + else + command.to_command_format + end + end + end + end + end + end +end -------------- next part -------------- HTML����������������������������... Download