proto-convert 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/proto-convert +60 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f67f667815700542bc0c6521ea0e4fff322ecfb22d13a0786d21cfef2b20bce
4
- data.tar.gz: 93f0f6e903b2fc6611d639a03d466dc7a5c0634e0a63220e66c5d8c1446616b5
3
+ metadata.gz: 5538e9d2c6050048c066b5694afe9bced0bdf8f3a8bf383aee963a1a0cc39034
4
+ data.tar.gz: 1e0bf071c4b5b6e493a7bf966cb8a795cfe04d3323d66982195cdb1cb0bd42e7
5
5
  SHA512:
6
- metadata.gz: d534c44b363c47b670b76b54e36dbc5e2460418ab18d43c243c5ed256d133a216c14916ca75e0b4d78e14da7e9611e8d33f74b08370b78066bbca21379ac3c1e
7
- data.tar.gz: 7f455edf6d20dd47cc3800c44cad5a98b6ed2642f36cbc24ef9b7539a117c101b4b6c45827741f9571ef2e0294851e416a7e2719c15f2517d0f077025dc97125
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.2.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
- `protoc --ruby_out=#{file_dir} --proto_path=#{file_dir} #{file_path}`
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('-v', '--version', 'prints version information') do
149
- puts "#{$PROGRAM_NAME} #{VERSION}\n#{AUTHOR_INFO}\n#{AUTHOR_GITHUB}"
150
- exit
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! Use a single self-contianed .proto file! #{$ERROR_INFO}"
235
+ puts "ERROR: Possible 'import' issue! #{$ERROR_INFO}"
183
236
  exit 1
184
237
  rescue StandardError
185
238
  puts "ERROR: #{$ERROR_INFO}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proto-convert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Azeem Sajid