Skip to content

Commit

Permalink
update plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
blackroot committed Jan 11, 2023
1 parent 8c42a43 commit 0875f08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 7 additions & 12 deletions xcmd/hack/proto/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var CreateCmd = &cobra.Command{
return
}

plugins := []string{"protoc-gen-go", "protoc-gen-go-grpc", "protoc-gen-gin", "protoc-gen-openapiv2", "protoc-gen-validate", "wire", "protoc-go-inject-tag"}
plugins := []string{"protoc-gen-go", "protoc-gen-go-grpc", "protoc-gen-gin", "protoc-gen-openapiv2", "protoc-gen-validate", "protoc-go-inject-tag"}
err := find(plugins...)
if err != nil {
cmd := exec.Command("hack", "install")
Expand Down Expand Up @@ -104,8 +104,6 @@ func create(path, dir string) error {
return fd.Run()
}

// inject-tag

func injectTag(dir string) error {
cmd := exec.Command("bash", "-c", fmt.Sprintf("find %s -name *.pb.go -type f ! -name *_http.pb.go -type f ! -name *_grpc.pb.go", dir))
var stdOut, stdErr bytes.Buffer
Expand All @@ -115,30 +113,27 @@ func injectTag(dir string) error {
fmt.Println(cmd.String())
}
err := cmd.Run()
outStr, errStr := stdOut.String(), stdErr.String()
outStr, _ := stdOut.String(), stdErr.String()
if err != nil {
fmt.Println("out str:", outStr)
fmt.Println("err str:", errStr)
fmt.Println("find err:", err)
fmt.Printf("find file fail, err:%+v\n", err)
return err
}
fmt.Println("5555:", errStr)
fmt.Print("77777:", outStr)

for _, file := range strings.Split(outStr, "\n") {
if len(file) == 0 {
continue
}
fmt.Println("file:", file)

cmd = exec.Command("protoc-go-inject-tag", "-input", file)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if debug {
fmt.Println(cmd.String())
}
err = cmd.Run()
if err != nil {
return err
}
}
return nil
}

// wire
3 changes: 1 addition & 2 deletions xcmd/hack/proto/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var InstallCmd = &cobra.Command{
"google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest",
"github.com/envoyproxy/protoc-gen-validate@latest",
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest",
"github.com/google/wire/cmd/wire@latest",
"github.com/favadi/protoc-go-inject-tag@latest",
"github.com/smallfish-root/common-pkg/xcmd/protoc-gen-gin@latest",
}
for _, plugin := range plugins {
fmt.Printf("go install %s\n", plugin)
Expand Down

0 comments on commit 0875f08

Please sign in to comment.