proto-convert 0.2.0 → 0.3.0
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 +4 -4
- data/bin/proto-convert +60 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5538e9d2c6050048c066b5694afe9bced0bdf8f3a8bf383aee963a1a0cc39034
|
4
|
+
data.tar.gz: 1e0bf071c4b5b6e493a7bf966cb8a795cfe04d3323d66982195cdb1cb0bd42e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 462d652162fc52893b8b7799afceba2f595b0b9aba813d4c38abc0c4f37b48f10b13ba9b03c4ce644905ed1da179f5845506728b6f2b019f5dd976f260a32af7
|
7
|
+
data.tar.gz: c7e225689e68e81e9fceab2c8a861eab48c134a65204a7113856b19e1c95583ce24fcd1f4387099f26496ae2ae7458bf57499097200f0c4b5a960941bd416349
|
data/bin/proto-convert
CHANGED
@@ -32,26 +32,54 @@
|
|
32
32
|
require 'optparse'
|
33
33
|
require 'English'
|
34
34
|
|
35
|
-
VERSION = '0.
|
35
|
+
VERSION = '0.3.0'
|
36
36
|
AUTHOR_NAME = 'Azeem Sajid'
|
37
37
|
AUTHOR_EMAIL = '<azeem.sajid@gmail.com>'
|
38
38
|
AUTHOR_INFO = "Author: #{AUTHOR_NAME} #{AUTHOR_EMAIL}"
|
39
39
|
AUTHOR_GITHUB = 'GitHub: https://github.com/iamAzeem/proto-convert'
|
40
40
|
|
41
|
+
$debug = false
|
42
|
+
|
41
43
|
def compile_proto(filename)
|
44
|
+
puts "\n>> Compiling [#{filename}]" if $debug
|
45
|
+
|
42
46
|
file_path = File.expand_path(filename)
|
43
47
|
file_dir = File.dirname(file_path)
|
44
48
|
|
45
|
-
|
49
|
+
if $debug
|
50
|
+
puts " File path: #{file_path}"
|
51
|
+
protoc_version = `protoc --version`.chomp.split(' ')[1]
|
52
|
+
puts " Running protoc #{protoc_version}:"
|
53
|
+
end
|
54
|
+
|
55
|
+
protoc_cmd =
|
56
|
+
" protoc \\\n" \
|
57
|
+
" --ruby_out=#{file_dir} \\\n" \
|
58
|
+
" --proto_path=#{file_dir} \\\n" \
|
59
|
+
" #{file_path}"
|
60
|
+
|
61
|
+
puts "\n#{protoc_cmd}" if $debug
|
62
|
+
|
63
|
+
`#{protoc_cmd}`
|
46
64
|
raise StandardError, "Invalid schema! [#{filename}] Resolve error(s)." unless $CHILD_STATUS.success?
|
47
65
|
|
66
|
+
puts "\n Compiled [#{file_path}] " if $debug
|
67
|
+
|
48
68
|
compiled_proto = "#{file_dir}/#{File.basename(file_path, '.proto')}_pb.rb"
|
69
|
+
puts " Validating [#{compiled_proto}]" if $debug
|
49
70
|
raise StandardError, "Compiled schema not found! [#{compiled_proto}]" unless File.file?(compiled_proto)
|
50
71
|
|
72
|
+
if $debug
|
73
|
+
puts " Validatd [#{compiled_proto}]"
|
74
|
+
puts "<< Compilion and validation complete! [#{file_path} => #{compiled_proto}]"
|
75
|
+
end
|
76
|
+
|
51
77
|
compiled_proto
|
52
78
|
end
|
53
79
|
|
54
80
|
def valid_msgtype?(compiled_proto, msg_type)
|
81
|
+
puts "\n>> Validating msgtype [#{msg_type}] in [#{compiled_proto}]" if $debug
|
82
|
+
|
55
83
|
msg_types = []
|
56
84
|
File.foreach(compiled_proto) do |line|
|
57
85
|
if line.lstrip.start_with?('add_message')
|
@@ -60,7 +88,19 @@ def valid_msgtype?(compiled_proto, msg_type)
|
|
60
88
|
end
|
61
89
|
end
|
62
90
|
|
63
|
-
msg_types.include?(msg_type)
|
91
|
+
is_valid = msg_types.include?(msg_type)
|
92
|
+
|
93
|
+
if $debug
|
94
|
+
puts " msgtype [#{msg_type}] available? #{is_valid ? 'yes' : 'no'}"
|
95
|
+
puts ' Available types:'
|
96
|
+
msg_types.each do |t|
|
97
|
+
puts " - #{t}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
puts "<< Validation of msgtype [#{msg_type}] complete!" if $debug
|
102
|
+
|
103
|
+
is_valid
|
64
104
|
end
|
65
105
|
|
66
106
|
def msg_class(compiled_proto, msg_type)
|
@@ -70,6 +110,8 @@ def msg_class(compiled_proto, msg_type)
|
|
70
110
|
end
|
71
111
|
|
72
112
|
def convert(compiled_proto, msg_type, conversion_mode, input_file, output_file)
|
113
|
+
puts "\n>> Converting [#{input_file}], mode: #{conversion_mode}" if $debug
|
114
|
+
|
73
115
|
pb_msg_class = msg_class(compiled_proto, msg_type)
|
74
116
|
raise StandardError, "Message type ['#{msg_type}'] not registered!'" if pb_msg_class.nil?
|
75
117
|
|
@@ -99,6 +141,8 @@ def convert(compiled_proto, msg_type, conversion_mode, input_file, output_file)
|
|
99
141
|
rescue StandardError
|
100
142
|
raise StandardError, "Conversion failed! #{$ERROR_INFO}"
|
101
143
|
end
|
144
|
+
|
145
|
+
puts ">> Converion complete! [#{input_file}] => [#{output_file}]" if $debug
|
102
146
|
end
|
103
147
|
|
104
148
|
def start
|
@@ -145,9 +189,9 @@ def start
|
|
145
189
|
options[:output] = filename
|
146
190
|
end
|
147
191
|
|
148
|
-
opts.on('-
|
149
|
-
|
150
|
-
|
192
|
+
opts.on('-d', '--debug', 'prints debugging information') do
|
193
|
+
options[:debug] = true
|
194
|
+
$debug = true
|
151
195
|
end
|
152
196
|
|
153
197
|
opts.on('-h', '--help', 'prints help') do
|
@@ -159,11 +203,20 @@ def start
|
|
159
203
|
begin
|
160
204
|
parser.parse!
|
161
205
|
|
206
|
+
puts ">> #{$PROGRAM_NAME} #{VERSION} [debug mode]" if $debug
|
207
|
+
|
162
208
|
# Validate missing mandatory arguments
|
163
209
|
missing_args = mandatory_args.select { |arg| options[arg].nil? }
|
164
210
|
raise OptionParser::MissingArgument, 'No arguments provided!' if missing_args.length == mandatory_args.length
|
165
211
|
raise OptionParser::MissingArgument, "--#{missing_args.join(', --')}" unless missing_args.empty?
|
166
212
|
|
213
|
+
if $debug
|
214
|
+
puts "\n>> Arguments:"
|
215
|
+
options.each do |arg, val|
|
216
|
+
puts format(' %<arg>8s : %<val>s', arg: arg, val: val)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
167
220
|
# Compile and validate proto and msgtype
|
168
221
|
compiled_proto = compile_proto(options[:proto])
|
169
222
|
msg_type = options[:msgtype]
|
@@ -179,7 +232,7 @@ def start
|
|
179
232
|
puts "\n#{$PROGRAM_NAME} #{VERSION}\n\n#{parser}\n#{AUTHOR_INFO}"
|
180
233
|
exit 1
|
181
234
|
rescue LoadError
|
182
|
-
puts "Possible 'import' issue!
|
235
|
+
puts "ERROR: Possible 'import' issue! #{$ERROR_INFO}"
|
183
236
|
exit 1
|
184
237
|
rescue StandardError
|
185
238
|
puts "ERROR: #{$ERROR_INFO}"
|