proto_plugin 0.1.0.pre.alpha.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -1
- data/exe/protoc-gen-proto-plugin-demo +17 -0
- data/lib/proto_plugin/base.rb +48 -0
- data/lib/proto_plugin/version.rb +1 -1
- data/lib/proto_plugin.rb +1 -0
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f4f3743b30d3c4f264e7756c603da53e14566c2e414b45cf2da7918635a103
|
4
|
+
data.tar.gz: 66cc63cd84cc91c179f0b25e9401d9f23e5d1d7cb678387dd604275abe09e240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6830929a04b8e7464797a2d5c4129d6840246f09b4ace2e77c7cebc5ce63d49b1a4d016e66c85f8dd0d9acf86c5ae675ed99f22a882d85f8c4feb697ea5124d
|
7
|
+
data.tar.gz: c2c9786adcf0530eec151fd445877788d2786b22fb0c9a3c23b8a9080a7ca27277f2b756a6deaead8a1c700e86ce66ccfb87672a1d7d4431798c9ad48880f5aa
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
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
|
data/lib/proto_plugin/version.rb
CHANGED
data/lib/proto_plugin.rb
CHANGED
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proto_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Baker
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-09-21 00:00:00.000000000 Z
|
@@ -24,16 +24,19 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.28'
|
27
|
-
description:
|
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:
|
@@ -42,23 +45,23 @@ metadata:
|
|
42
45
|
homepage_uri: https://github.com/cocoahero/proto_plugin
|
43
46
|
source_code_uri: https://github.com/cocoahero/proto_plugin
|
44
47
|
allowed_push_host: https://rubygems.org
|
45
|
-
post_install_message:
|
48
|
+
post_install_message:
|
46
49
|
rdoc_options: []
|
47
50
|
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
|
56
|
+
version: '3.0'
|
54
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
58
|
requirements:
|
56
59
|
- - ">="
|
57
60
|
- !ruby/object:Gem::Version
|
58
61
|
version: '0'
|
59
62
|
requirements: []
|
60
|
-
rubygems_version: 3.5.
|
61
|
-
signing_key:
|
63
|
+
rubygems_version: 3.5.11
|
64
|
+
signing_key:
|
62
65
|
specification_version: 4
|
63
66
|
summary: Easily build `protoc` plugins in Ruby.
|
64
67
|
test_files: []
|