proto_plugin 0.1.0.pre.alpha.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a1f639a6d10b3b1453fe175009232fc1e1b548c4b93b7075e336b548c9a71bf
4
- data.tar.gz: '008f968744cc7f74d42df472d1b191a71752973ad9ebba255673d4db4c594f28'
3
+ metadata.gz: 96f4f3743b30d3c4f264e7756c603da53e14566c2e414b45cf2da7918635a103
4
+ data.tar.gz: 66cc63cd84cc91c179f0b25e9401d9f23e5d1d7cb678387dd604275abe09e240
5
5
  SHA512:
6
- metadata.gz: 97fc2b8b9e3d1687d987696a95b479c816937ab0ff92d20e929974dc9884e9d60ff869392fa29eec69285531965a73da35146a88f62e07bcf320efbda85000be
7
- data.tar.gz: 82546a40d21f5c5f893fcd89df670667743f0b15cc133134cfbe68ee997cf157a9544ee46bb97ea3f180115f89d5e98ae7671c38cdd44fd6f1b7905fa6021d1f
6
+ metadata.gz: d6830929a04b8e7464797a2d5c4129d6840246f09b4ace2e77c7cebc5ce63d49b1a4d016e66c85f8dd0d9acf86c5ae675ed99f22a882d85f8c4feb697ea5124d
7
+ data.tar.gz: c2c9786adcf0530eec151fd445877788d2786b22fb0c9a3c23b8a9080a7ca27277f2b756a6deaead8a1c700e86ce66ccfb87672a1d7d4431798c9ad48880f5aa
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- # Proto::Plugin
1
+ # ProtoPlugin
2
2
 
3
+ [![Lint](https://github.com/cocoahero/proto_plugin/actions/workflows/lint.yml/badge.svg)](https://github.com/cocoahero/proto_plugin/actions/workflows/lint.yml)
4
+ [![Test](https://github.com/cocoahero/proto_plugin/actions/workflows/test.yml/badge.svg)](https://github.com/cocoahero/proto_plugin/actions/workflows/test.yml)
3
5
  [![Gem Version](https://badge.fury.io/rb/proto_plugin.svg)](https://badge.fury.io/rb/proto_plugin)
4
6
 
5
7
  ## Installation
@@ -8,6 +10,50 @@
8
10
  gem install proto_plugin
9
11
  ```
10
12
 
13
+ ## Usage
14
+
15
+ Creating a `protoc` plugin is as simple as creating a new executable script.
16
+
17
+ The name of the file must follow the format `protoc-gen-[plugin-name]`. As an example, the below file could be named `protoc-gen-mycoolplugin`.
18
+
19
+ ```ruby
20
+ #! /usr/bin/env ruby
21
+
22
+ require "proto_plugin"
23
+
24
+ class MyCoolPlugin < ProtoPlugin::Base
25
+ def run
26
+ request.file_to_generate.each do |f|
27
+ name = File.basename(f, ".proto")
28
+
29
+ add_file(name: "#{name}.txt", content: <<~TXT)
30
+ This file was generated from #{name}.proto!
31
+ TXT
32
+ end
33
+ end
34
+ end
35
+
36
+ MyCoolPlugin.run!
37
+ ```
38
+
39
+ To invoke the plugin, first make sure you have `protoc` [installed](https://github.com/protocolbuffers/protobuf#protobuf-compiler-installation). Then in a terminal, run:
40
+
41
+ ```bash
42
+ protoc --plugin=path/to/protoc-gen-mycoolplugin --mycoolplugin_out=. input.proto
43
+ ```
44
+
45
+ If the executable script is in your `$PATH`, for example installed via a gem, you can omit the `--plugin` argument.
46
+
47
+ ```bash
48
+ protoc --mycoolplugin_out=. input.proto
49
+ ```
50
+
51
+ See [`exe/protoc-gen-proto-plugin-demo`](./exe/protoc-gen-proto-plugin-demo) in this repo as another example of a plugin. Since it should be in your `$PATH` (you did install this gem right?) you can invoke it with:
52
+
53
+ ```bash
54
+ protoc --proto-plugin-demo_out=. input.proto
55
+ ```
56
+
11
57
  ## Development
12
58
 
13
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,17 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "proto_plugin"
5
+
6
+ class Demo < ProtoPlugin::Base
7
+ def run
8
+ request.file_to_generate.each do |f|
9
+ name = File.basename(f, ".proto")
10
+ add_file(name: "#{name}.txt", content: <<~TXT)
11
+ This file was generated from #{name}.proto!
12
+ TXT
13
+ end
14
+ end
15
+ end
16
+
17
+ Demo.run!
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "google/protobuf"
4
+ require "google/protobuf/plugin_pb"
5
+
6
+ module ProtoPlugin
7
+ class Base
8
+ class << self
9
+ def run!(input: $stdin, output: $stdout)
10
+ plugin = new(
11
+ request: Google::Protobuf::Compiler::CodeGeneratorRequest.decode(
12
+ input.read,
13
+ ),
14
+ )
15
+
16
+ plugin.run
17
+
18
+ result = plugin.response
19
+ output.write(result.to_proto)
20
+ result
21
+ end
22
+ end
23
+
24
+ attr_reader :request
25
+
26
+ attr_reader :response
27
+
28
+ def initialize(request:)
29
+ @request = request
30
+ @response = Google::Protobuf::Compiler::CodeGeneratorResponse.new(
31
+ supported_features: supported_features.reduce(&:|),
32
+ )
33
+ end
34
+
35
+ def supported_features
36
+ [Google::Protobuf::Compiler::CodeGeneratorResponse::Feature::FEATURE_NONE]
37
+ end
38
+
39
+ def add_file(name:, content:)
40
+ @response.file << Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(
41
+ name: name, content: content,
42
+ )
43
+ end
44
+
45
+ def run
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProtoPlugin
4
- VERSION = "0.1.0.pre.alpha.2"
4
+ VERSION = "0.1.0"
5
5
  end
data/lib/proto_plugin.rb CHANGED
@@ -4,3 +4,4 @@ module ProtoPlugin
4
4
  end
5
5
 
6
6
  require_relative "proto_plugin/version"
7
+ require_relative "proto_plugin/base"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proto_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.alpha.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Baker
@@ -27,13 +27,16 @@ dependencies:
27
27
  description:
28
28
  email:
29
29
  - jonathan@jmb.dev
30
- executables: []
30
+ executables:
31
+ - protoc-gen-proto-plugin-demo
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
34
  files:
34
35
  - LICENSE.txt
35
36
  - README.md
37
+ - exe/protoc-gen-proto-plugin-demo
36
38
  - lib/proto_plugin.rb
39
+ - lib/proto_plugin/base.rb
37
40
  - lib/proto_plugin/version.rb
38
41
  homepage: https://github.com/cocoahero/proto_plugin
39
42
  licenses:
@@ -48,9 +51,9 @@ require_paths:
48
51
  - lib
49
52
  required_ruby_version: !ruby/object:Gem::Requirement
50
53
  requirements:
51
- - - ">="
54
+ - - "~>"
52
55
  - !ruby/object:Gem::Version
53
- version: 3.0.0
56
+ version: '3.0'
54
57
  required_rubygems_version: !ruby/object:Gem::Requirement
55
58
  requirements:
56
59
  - - ">="