grn2drn 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4940edafe622781d134c34040b00f8334c10dd49
4
- data.tar.gz: ee1a8d7a39e90e1f7eea163233c6290aded4ac90
3
+ metadata.gz: 6c38fc6b9e7019672486a1116916fb1564dfb8b1
4
+ data.tar.gz: d8ba21de8b5bac4ccf19e25c6f610d3de3509481
5
5
  SHA512:
6
- metadata.gz: b90c36e609d65ae8555f7176fb38a6236f649ffdb5232e788abf3b5bca542dff3f1ec337e545e7fb89a46ba5ec54256c5074bfae615437c08b7f40c92989c5b4
7
- data.tar.gz: 57500ec0df6177e1399641d305deb8903138092c2e17f4d54950b6d71628bd1273e83d1758e27d26af7d618ce2de0a0c940f2eff4b7680948b8cab4ed5c5d005
6
+ metadata.gz: 7bacff4c438d035c04b346e22900e36d94f52e761125d14d1839c3bda590d1ccb4dce6307d492203f792f04ea96fae9224c4c6b320324f8dfd61ebccff71f547
7
+ data.tar.gz: 156ed4acd12d07cbc810f4887835e752296fd160410eccd9a5fcc93510c0dffb45512e7671b371465ec4553124a11e0b1988f4d195fa899f1089b366da4471bf
data/bin/grn2drn CHANGED
@@ -22,7 +22,10 @@ require "optparse"
22
22
  require "grn2drn/command-converter"
23
23
 
24
24
  options = OpenStruct.new
25
+ options.output_path = "-"
25
26
  option_parser = OptionParser.new do |parser|
27
+ parser.banner += " INPUT"
28
+
26
29
  parser.separator("")
27
30
  parser.separator("Converts Groonga commands to Droonga messages")
28
31
 
@@ -50,11 +53,18 @@ option_parser = OptionParser.new do |parser|
50
53
  "Responses from Droonga engine will be sent to TO.") do |to|
51
54
  options.reply_to = to
52
55
  end
56
+
57
+ parser.on("--output=PATH",
58
+ "Output Droonga messages to PATH.",
59
+ "\"-\" means the standard output.",
60
+ "(#{options.output_path})") do |path|
61
+ options.output_path = path
62
+ end
53
63
  end
54
- args = option_parser.parse!(ARGV)
64
+ option_parser.parse!(ARGV)
55
65
 
56
66
  if options.dataset.nil?
57
- puts("--dataset option is missed.")
67
+ $stderr.puts("--dataset option is missed.")
58
68
  exit(false)
59
69
  end
60
70
 
@@ -66,9 +76,6 @@ convert_options = {
66
76
  }
67
77
  converter = Grn2Drn::CommandConverter.new(convert_options)
68
78
 
69
- source_file = args[0]
70
- result_file = args[1]
71
-
72
79
  def open_input(source_file)
73
80
  if source_file.nil?
74
81
  yield($stdin)
@@ -79,20 +86,18 @@ def open_input(source_file)
79
86
  end
80
87
  end
81
88
 
82
- def open_output(result_file)
83
- if result_file.nil?
89
+ def open_output(path)
90
+ if path == "-"
84
91
  yield($stdout)
85
92
  else
86
- File.open("w", result_file) do |output|
93
+ File.open(path, "w") do |output|
87
94
  yield(output)
88
95
  end
89
96
  end
90
97
  end
91
98
 
92
- open_input(source_file) do |input|
93
- open_output(result_file) do |output|
94
- converter.convert(input) do |command|
95
- output.puts(JSON.generate(command))
96
- end
99
+ open_output(options.output_path) do |output|
100
+ converter.convert(ARGF) do |command|
101
+ output.puts(JSON.generate(command))
97
102
  end
98
103
  end
data/bin/grn2drn-schema CHANGED
@@ -16,15 +16,49 @@
16
16
  # License along with this library; if not, write to the Free Software
17
17
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 
19
+ require "ostruct"
20
+ require "optparse"
19
21
  require "json"
20
22
 
21
23
  require "grn2drn/schema-converter"
22
24
 
25
+ def open_output(path)
26
+ if path == "-"
27
+ yield($stdout)
28
+ else
29
+ File.open(path, "w") do |output|
30
+ yield(output)
31
+ end
32
+ end
33
+ end
34
+
35
+ options = OpenStruct.new
36
+ options.output_path = "-"
37
+ option_parser = OptionParser.new do |parser|
38
+ parser.banner += " INPUT"
39
+
40
+ parser.separator("")
41
+ parser.separator("Converts Groonga schema to Droonga schema")
42
+
43
+ parser.separator("")
44
+ parser.separator("Optional parameters:")
45
+ parser.on("--output=PATH",
46
+ "Output Droonga messages to PATH.",
47
+ "\"-\" means the standard output.",
48
+ "(#{options.output_path})") do |path|
49
+ options.output_path = path
50
+ end
51
+ end
52
+ option_parser.parse!(ARGV)
53
+
23
54
  converter = Grn2Drn::SchemaConverter.new
24
55
  begin
25
56
  schema = converter.convert(ARGF)
26
57
  rescue Grn2Drn::Error
27
- puts($!.message)
58
+ $stderr.puts($!.message)
28
59
  exit(false)
29
60
  end
30
- puts(JSON.pretty_generate(schema))
61
+
62
+ open_output(options.output_path) do |output|
63
+ output.puts(JSON.pretty_generate(schema))
64
+ end
@@ -14,5 +14,5 @@
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
  module Grn2Drn
17
- VERSION = "1.0.1"
17
+ VERSION = "1.0.2"
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grn2drn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droonga Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-29 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -112,8 +112,8 @@ description: ''
112
112
  email:
113
113
  - droonga@groonga.org
114
114
  executables:
115
- - grn2drn
116
115
  - grn2drn-schema
116
+ - grn2drn
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
@@ -121,12 +121,12 @@ files:
121
121
  - Rakefile
122
122
  - Gemfile
123
123
  - grn2drn.gemspec
124
- - lib/grn2drn/command-converter.rb
125
- - lib/grn2drn/version.rb
126
124
  - lib/grn2drn/error.rb
125
+ - lib/grn2drn/version.rb
127
126
  - lib/grn2drn/schema-converter.rb
128
- - bin/grn2drn
127
+ - lib/grn2drn/command-converter.rb
129
128
  - bin/grn2drn-schema
129
+ - bin/grn2drn
130
130
  homepage: https://github.com/droonga/grn2drn
131
131
  licenses:
132
132
  - GPLv3 or later
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.0.13
150
+ rubygems_version: 2.0.14
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Grn2drn is a command to convert a *.grn dump file to a JSONs file for Droonga.