[Groonga-commit] droonga/grn2drn at d3b7183 [master] Add --output option

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 4 17:17:48 JST 2014


Kouhei Sutou	2014-04-04 17:17:48 +0900 (Fri, 04 Apr 2014)

  New Revision: d3b71838eaf3f84e9bf6765a9fc84d252a06ee94
  https://github.com/droonga/grn2drn/commit/d3b71838eaf3f84e9bf6765a9fc84d252a06ee94

  Message:
    Add --output option

  Modified files:
    bin/grn2drn-schema

  Modified: bin/grn2drn-schema (+35 -1)
===================================================================
--- bin/grn2drn-schema    2014-04-04 17:17:39 +0900 (049203a)
+++ bin/grn2drn-schema    2014-04-04 17:17:48 +0900 (0f9f99c)
@@ -16,10 +16,41 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+require "ostruct"
+require "optparse"
 require "json"
 
 require "grn2drn/schema-converter"
 
+def open_output(path)
+  if path == "-"
+    yield($stdout)
+  else
+    File.open(path, "w") do |output|
+      yield(output)
+    end
+  end
+end
+
+options = OpenStruct.new
+options.output_path = "-"
+option_parser = OptionParser.new do |parser|
+  parser.banner += " INPUT"
+
+  parser.separator("")
+  parser.separator("Converts Groonga schema to Droonga schema")
+
+  parser.separator("")
+  parser.separator("Optional parameters:")
+  parser.on("--output=PATH",
+            "Output Droonga messages to PATH.",
+            "\"-\" means the standard output.",
+            "(#{options.output_path})") do |path|
+    options.output_path = path
+  end
+end
+option_parser.parse!(ARGV)
+
 converter = Grn2Drn::SchemaConverter.new
 begin
   schema = converter.convert(ARGF)
@@ -27,4 +58,7 @@ rescue Grn2Drn::Error
   $stderr.puts($!.message)
   exit(false)
 end
-puts(JSON.pretty_generate(schema))
+
+open_output(options.output_path) do |output|
+  output.puts(JSON.pretty_generate(schema))
+end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index