Protoc Gen Whatever banner
ngerakines ngerakines

Protoc Gen Whatever

Development community

Description

A protoc plugin use to generate arbitrary files from protocol buffer definitions.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

protoc-gen-whatever

This is a plugin that allows for protocol buffer definitions to be used as inputs to Golang's text template library to generate files.

Installation

Instlal with `go get`.

$ go get -u github.com/ngerakines/protoc-gen-whatever/cmd/protoc-gen-whatever

Plugin Configuration

This plugin is used when the `--whatever_out` and `--whatever_opt` arguments are provided to the base `protoc` command.

The `--whatever_out` argument is used to set the location of generated output files.

The `--whatever_opt` argument is used to set the input template and optional output file name. This argument is optional and defaults to `--whatever_opt=whatever.tpl`.

For example, with `--whatever_out=. --whatever_opt=input.tpl` the plugin will look for a file named `input.tpl` in the current working directory and generate a file namee `output` in the current working directory.

With `--whatever_out=cmd --whatever_opt=templates/cobra.tpl,commands.go`, the plugin will look for the `templates/cobra.tpl` file as the template and render the file `cmd/commands.go`.

Templates

The input to the template is the `CodeGeneratorRequest` structure as defined in `google/protobuf/compiler/plugin.proto`.

Usage

With the proto file `simple.proto`:

syntax = "proto3";

package test;

message Example {
    string label = 1;
}

service Foo {
    rpc GetFoo(GetFooReq) returns (GetFooRes);
}

message GetFooReq {

}

message GetFooRes {

}

And the template file `simple.tpl`:

{{.Name}}{{range .MessageType}}
*{{.Name}}{{end}}

Running the command:

$ protoc --plugin=./protoc-gen-whatever --whatever_out=. --whatever_opt=./test/simple.tpl,output.txt ./test/simple.proto

Yields the file `output.txt`:

simple.proto
*Example
*GetFooReq
*GetFooRes

Testing

$ protoc --go_out=plugins=grpc:. test/*.proto

Release

To release new versions, use [mage](https://github.com/magefile/mage).

$ go get github.com/goreleaser/goreleaser
$ go ge