groonga-command-parser 1.0.2 → 1.0.3

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: 6586a6d72a155715ad67c47652183969cf9a5255
4
- data.tar.gz: a3879393e9c3d9f09718c8f253b2cdc86be05119
3
+ metadata.gz: a842fe9087d59d4d37a94dba22f419576d192b09
4
+ data.tar.gz: 60a05fe87c274df64c6abd2e9d14c33162999d9d
5
5
  SHA512:
6
- metadata.gz: 7354d617dd59ffba8f795c914b73a439eee43a03916a6eea2bd7843aa02fcdaaa53c0a57dc756f308a49e77f1a90e1bd29c171c463bf2ca8972447738d1509ba
7
- data.tar.gz: 9abeebb9d08f1af5866533f0599e7e09bde3ca2be723716863822d7a2a36a80db6f0f2832ecb183210456fb4f1e650a4350e07e5797732f7ab1b313fbec00913
6
+ metadata.gz: a4bee897857636e1286a8e49bd6b1a1ba49d6e1351cff6280dbb75a447855482efeea89de190ce899fdaa169020fcdd59dd6691a93ce67c0d89794d7a729d1c9
7
+ data.tar.gz: 79ef8b01fd136994a4782e3137c65b7a59159318e2c640dd3e6ebdf98a5ef1bb29bba036561514e665701c5558dee15144e370e46bb4fa9b739aafa875b3e7fb
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/command/parser/command/groonga-command-convert-format"
20
+
21
+ command = Groonga::Command::Parser::Command::GroongaCommandConvertFormat.new
22
+ exit(command.run(ARGV))
data/doc/text/news.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # News
2
2
 
3
+ ## 1.0.3: 2014-12-12
4
+
5
+ ### Improvements
6
+
7
+ * Added "groonga-command-convert-format" command that converts
8
+ command format.
9
+
3
10
  ## 1.0.2: 2014-10-02
4
11
 
5
12
  ### Improvements
@@ -44,9 +44,9 @@ Gem::Specification.new do |spec|
44
44
  spec.files += Dir.glob("lib/**/*.rb")
45
45
  spec.files += Dir.glob("doc/text/*")
46
46
  spec.test_files += Dir.glob("test/**/*")
47
- # Dir.chdir("bin") do
48
- # spec.executables = Dir.glob("*")
49
- # end
47
+ Dir.chdir("bin") do
48
+ spec.executables = Dir.glob("*")
49
+ end
50
50
 
51
51
  spec.homepage = "https://github.com/groonga/groonga-command-parser"
52
52
  spec.licenses = ["LGPLv2.1+"]
@@ -369,7 +369,7 @@ module Groonga
369
369
  end
370
370
  name, output_type = name.split(/\./, 2)
371
371
  arguments["output_type"] = output_type if output_type
372
- command_class = Command.find(name)
372
+ command_class = ::Groonga::Command.find(name)
373
373
  command = command_class.new(name, arguments)
374
374
  command.original_format = :uri
375
375
  command.path_prefix = prefix
@@ -400,7 +400,7 @@ module Groonga
400
400
  ordered_arguments << argument
401
401
  end
402
402
  end
403
- command_class = Command.find(name)
403
+ command_class = ::Groonga::Command.find(name)
404
404
  command = command_class.new(name, pair_arguments, ordered_arguments)
405
405
  command.original_format = :command
406
406
  command
@@ -0,0 +1,98 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "optparse"
18
+
19
+ require "groonga/command/parser"
20
+
21
+ module Groonga
22
+ module Command
23
+ class Parser
24
+ module Command
25
+ class GroongaCommandConvertFormat
26
+ def initialize
27
+ @format = :command
28
+ @uri_prefix = "http://localhost:10041"
29
+ end
30
+
31
+ def run(argv=ARGV)
32
+ begin
33
+ parse_options!(argv)
34
+ rescue OptionParser::ParseError
35
+ puts($!.message)
36
+ return false
37
+ end
38
+
39
+ input_paths = argv
40
+ if input_paths.empty?
41
+ convert($stdin)
42
+ else
43
+ input_paths.each do |input_path|
44
+ File.open(input_path) do |input|
45
+ convert(input)
46
+ end
47
+ end
48
+ end
49
+
50
+ true
51
+ end
52
+
53
+ private
54
+ def parse_options!(argv)
55
+ option_parser = OptionParser.new
56
+ option_parser.banner += " INPUT_PATH1 INPUT_PATH2 ..."
57
+ option_parser.version = VERSION
58
+
59
+ formats = [:uri, :command]
60
+ option_parser.on("--format=FORMAT", formats,
61
+ "Convert to FORMAT",
62
+ "Available formats #{formats.join(', ')}",
63
+ "[#{@format}]") do |format|
64
+ @format = format
65
+ end
66
+
67
+ option_parser.on("--uri-prefix=PREFIX",
68
+ "Add PREFIX to URI",
69
+ "[#{@uri_prefix}]") do |prefix|
70
+ @uri_prefix = prefix
71
+ end
72
+
73
+ option_parser.parse!(argv)
74
+ end
75
+
76
+ def convert(input)
77
+ parser = Parser.new
78
+ parser.on_command do |command|
79
+ puts(convert_format(command))
80
+ end
81
+ input.each_line do |line|
82
+ parser << line
83
+ end
84
+ end
85
+
86
+ def convert_format(command)
87
+ case @format
88
+ when :uri
89
+ "#{@uri_prefix}#{command.to_uri_format}"
90
+ else
91
+ command.to_command_format
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@
19
19
  module Groonga
20
20
  module Command
21
21
  class Parser
22
- VERSION = "1.0.2"
22
+ VERSION = "1.0.3"
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-command-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-02 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groonga-command
@@ -139,7 +139,8 @@ dependencies:
139
139
  description: ''
140
140
  email:
141
141
  - kou@clear-code.com
142
- executables: []
142
+ executables:
143
+ - groonga-command-convert-format
143
144
  extensions: []
144
145
  extra_rdoc_files: []
145
146
  files:
@@ -147,10 +148,12 @@ files:
147
148
  - Gemfile
148
149
  - README.md
149
150
  - Rakefile
151
+ - bin/groonga-command-convert-format
150
152
  - doc/text/lgpl-2.1.txt
151
153
  - doc/text/news.md
152
154
  - groonga-command-parser.gemspec
153
155
  - lib/groonga/command/parser.rb
156
+ - lib/groonga/command/parser/command/groonga-command-convert-format.rb
154
157
  - lib/groonga/command/parser/error.rb
155
158
  - lib/groonga/command/parser/version.rb
156
159
  - test/groonga-command-parser-test-utils.rb
@@ -182,7 +185,7 @@ specification_version: 4
182
185
  summary: Groonga-command-parser is a Ruby library to parses [groonga](http://groonga.org/)'s
183
186
  command syntax. You can write a program to process groonga's command by using groonga-command-parser.
184
187
  test_files:
185
- - test/groonga-command-parser-test-utils.rb
186
- - test/run-test.rb
187
188
  - test/test-parser.rb
189
+ - test/run-test.rb
190
+ - test/groonga-command-parser-test-utils.rb
188
191
  has_rdoc: