Skip to content

Commit

Permalink
made protoc-gen-gogo also use the vanity/command like all the other c…
Browse files Browse the repository at this point in the history
…ommands
  • Loading branch information
awalterschulze committed Sep 10, 2015
1 parent d8cee73 commit 10f623c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 134 deletions.
34 changes: 0 additions & 34 deletions protoc-gen-gogo/link_grpc.go

This file was deleted.

102 changes: 2 additions & 100 deletions protoc-gen-gogo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,107 +49,9 @@
package main

import (
"io/ioutil"
"os"

"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/protoc-gen-gogo/generator"

_ "github.com/gogo/protobuf/plugin/defaultcheck"
_ "github.com/gogo/protobuf/plugin/description"
_ "github.com/gogo/protobuf/plugin/embedcheck"
_ "github.com/gogo/protobuf/plugin/enumstringer"
_ "github.com/gogo/protobuf/plugin/equal"
_ "github.com/gogo/protobuf/plugin/face"
_ "github.com/gogo/protobuf/plugin/gostring"
_ "github.com/gogo/protobuf/plugin/marshalto"
_ "github.com/gogo/protobuf/plugin/oneofcheck"
_ "github.com/gogo/protobuf/plugin/populate"
_ "github.com/gogo/protobuf/plugin/size"
_ "github.com/gogo/protobuf/plugin/stringer"
_ "github.com/gogo/protobuf/plugin/union"
_ "github.com/gogo/protobuf/plugin/unmarshal"

"github.com/gogo/protobuf/plugin/testgen"

"go/format"
"strings"
"github.com/gogo/protobuf/vanity/command"
)

func main() {
// Begin by allocating a generator. The request and response structures are stored there
// so we can do error handling easily - the response structure contains the field to
// report failure.
g := generator.New()

dataIn, err := ioutil.ReadAll(os.Stdin)
if err != nil {
g.Error(err, "reading input")
}

if err := proto.Unmarshal(dataIn, g.Request); err != nil {
g.Error(err, "parsing input proto")
}

if len(g.Request.FileToGenerate) == 0 {
g.Fail("no files to generate")
}

g.CommandLineParameters(g.Request.GetParameter())

// Create a wrapped version of the Descriptors and EnumDescriptors that
// point to the file that defines them.
g.WrapTypes()

g.SetPackageNames()
g.BuildTypeNameMap()

g.GenerateAllFiles()

gtest := generator.New()

if err := proto.Unmarshal(dataIn, gtest.Request); err != nil {
gtest.Error(err, "parsing input proto")
}

if len(gtest.Request.FileToGenerate) == 0 {
gtest.Fail("no files to generate")
}

gtest.CommandLineParameters(gtest.Request.GetParameter())

// Create a wrapped version of the Descriptors and EnumDescriptors that
// point to the file that defines them.
gtest.WrapTypes()

gtest.SetPackageNames()
gtest.BuildTypeNameMap()

gtest.GeneratePlugin(testgen.NewPlugin())

for i := 0; i < len(gtest.Response.File); i++ {
if strings.Contains(*gtest.Response.File[i].Content, `//These tests are generated by github.com/gogo/protobuf/plugin/testgen`) {
gtest.Response.File[i].Name = proto.String(strings.Replace(*gtest.Response.File[i].Name, ".pb.go", "pb_test.go", -1))
g.Response.File = append(g.Response.File, gtest.Response.File[i])
}
}

for i := 0; i < len(g.Response.File); i++ {
formatted, ferr := format.Source([]byte(g.Response.File[i].GetContent()))
if ferr != nil {
g.Error(ferr, "go format error")
}
fmts := string(formatted)
g.Response.File[i].Content = &fmts
}

// Send back the results.
dataOut, err := proto.Marshal(g.Response)
if err != nil {
g.Error(err, "failed to marshal output proto")
}

if _, err := os.Stdout.Write(dataOut); err != nil {
g.Error(err, "failed to write output proto")
}
command.Write(command.Generate(command.Read()))
}

0 comments on commit 10f623c

Please sign in to comment.