YUKI Hiroshi
null+****@clear*****
Wed Sep 18 16:18:56 JST 2013
YUKI Hiroshi 2013-09-18 16:18:56 +0900 (Wed, 18 Sep 2013) New Revision: 3a4adfcb1e5c435780ecbacb65a0c0de4f59cc18 https://github.com/droonga/fluent-plugin-droonga/commit/3a4adfcb1e5c435780ecbacb65a0c0de4f59cc18 Message: Implement command to convert .grn files to .jsons files Added files: bin/grn2jsons Added: bin/grn2jsons (+61 -0) 100755 =================================================================== --- /dev/null +++ bin/grn2jsons 2013-09-18 16:18:56 +0900 (ebdd7cc) @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +require "groonga_command_converter" +require "json" +require "ostruct" +require "optparse" + +options = OpenStruct.new +option_parser = OptionParser.new do |parser| + parser.on("-i=ID", "--id=ID", + "base id. (optional)") do |id| + options.id = id + end + + parser.on("-d=DATE", "--date=DATE", + "date. (optional)") do |date| + options.date = date + end + + parser.on("-r=REPLYTO", "--reply-to=REPLYTO", + "value of replyTo field.") do |reply_to| + options.reply_to = reply_to + end + + parser.on("-s=DATASET", "--dataset=DATASET", + "dataset.") do |dataset| + options.dataset = dataset + end +end +args = option_parser.parse!(ARGV) + +convert_options = { + :id => options.id, + :date => options.date, + :reply_to => options.reply_to, + :dataset => options.dataset, +} + +source_file = args[0] +result_file = args[1] + +input = nil +if source_file.nil? + input = STDIN.read +else + input = File.read(source_file) +end + +result_file = args[1] +if result_file.nil? + converter.convert(input, convert_options) do |command| + puts(JSON.generate(command)) + end +else + File.open("w", result_file) do |file| + converter.convert(input, convert_options) do |command| + file.puts(JSON.generate(command)) + end + end +end -------------- next part -------------- HTML����������������������������... 下载