Skip to content

Commit

Permalink
feat: add -file flag to protoc-gen-go-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt committed Sep 6, 2021
1 parent 38b4edd commit 8b4b31f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
5 changes: 5 additions & 0 deletions cmd/protoc-gen-go-errors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package main
import (
"flag"
"fmt"
"path/filepath"

"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
Expand All @@ -41,12 +42,16 @@ func main() {
return
}
var flags flag.FlagSet
file := flags.String("file", "", "specified proto files (default value: errors.proto)")
protogen.Options{ParamFunc: flags.Set}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
for _, f := range gen.Files {
if !f.Generate {
continue
}
if filepath.Base(f.Proto.GetName()) != *file {
continue
}
generateFile(gen, f)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/errors/error.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
rm -rf ./protoc-gen-go-errors
go build -o ./protoc-gen-go-errors ../../../cmd/protoc-gen-go-errors
export PATH=$PATH:$(pwd)/
protoc --proto_path=. --go_out=paths=source_relative:. --go-errors_out=paths=source_relative:. ./myerr.proto
protoc --proto_path=. --go_out=paths=source_relative:. --go-errors_out=paths=source_relative,file=errors.proto:. ./errors.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.

0 comments on commit 8b4b31f

Please sign in to comment.