fix protoc check (#732)

pull/722/head
Tony Chen 4 years ago committed by GitHub
parent f984dc5c6d
commit 204bf7be87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/kratos/internal/base/get.go
  2. 17
      cmd/kratos/internal/proto/client/client.go

@ -1,6 +1,7 @@
package base
import (
"fmt"
"os"
"os/exec"
)
@ -8,6 +9,7 @@ import (
// GoGet go get path.
func GoGet(path ...string) error {
for _, p := range path {
fmt.Printf("go get -u %s\n", p)
cmd := exec.Command("go", "get", "-u", p)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

@ -30,10 +30,14 @@ func run(cmd *cobra.Command, args []string) {
err error
proto = strings.TrimSpace(args[0])
)
if _, err = exec.LookPath("protoc-gen-go-http"); err != nil {
if err = look("protoc-gen-go", "protoc-gen-go-grpc", "protoc-gen-go-http", "protoc-gen-go-errors"); err != nil {
// update the kratos plugins
if err := exec.Command("kratos", "upgrade").Run(); err != nil {
cmd := exec.Command("kratos", "upgrade")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if cmd.Run(); err != nil {
fmt.Println(err)
return
}
}
if strings.HasSuffix(proto, ".proto") {
@ -46,6 +50,15 @@ func run(cmd *cobra.Command, args []string) {
}
}
func look(name ...string) error {
for _, n := range name {
if _, err := exec.LookPath(n); err != nil {
return err
}
}
return nil
}
func walk(dir string) error {
if dir == "" {
dir = "."

Loading…
Cancel
Save