Skip to content

Commit

Permalink
Merge pull request #179 from sevennt/feature/go-errors-add-flag
Browse files Browse the repository at this point in the history
feat: add -file flag to protoc-gen-go-errors
  • Loading branch information
sevennt authored Sep 6, 2021
2 parents 38b4edd + 8b4b31f commit b6e2ece
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 b6e2ece

Please sign in to comment.