Merge pull request #398 from bilibili/tool/protoc

support *.proto
pull/403/head
Tony 5 years ago committed by GitHub
commit b30a6d8dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      tool/kratos-protoc/bm.go
  2. 6
      tool/kratos-protoc/ecode.go
  3. 6
      tool/kratos-protoc/grpc.go
  4. 20
      tool/kratos-protoc/protoc.go
  5. 6
      tool/kratos-protoc/swagger.go

@ -2,8 +2,6 @@ package main
import (
"os/exec"
"github.com/urfave/cli"
)
const (
@ -20,6 +18,6 @@ func installBMGen() error {
return nil
}
func genBM(ctx *cli.Context) error {
return generate(ctx, _bmProtoc)
func genBM(files []string) error {
return generate(_bmProtoc, files)
}

@ -2,8 +2,6 @@ package main
import (
"os/exec"
"github.com/urfave/cli"
)
const (
@ -20,6 +18,6 @@ func installEcodeGen() error {
return nil
}
func genEcode(ctx *cli.Context) error {
return generate(ctx, _ecodeProtoc)
func genEcode(files []string) error {
return generate(_ecodeProtoc, files)
}

@ -2,8 +2,6 @@ package main
import (
"os/exec"
"github.com/urfave/cli"
)
const (
@ -20,6 +18,6 @@ func installGRPCGen() error {
return nil
}
func genGRPC(ctx *cli.Context) error {
return generate(ctx, _grpcProtoc)
func genGRPC(files []string) error {
return generate(_grpcProtoc, files)
}

@ -27,6 +27,10 @@ func protocAction(ctx *cli.Context) (err error) {
if err = checkProtoc(); err != nil {
return err
}
files := []string(ctx.Args())
if len(files) == 0 {
files, _ = filepath.Glob("*.proto")
}
if !withGRPC && !withBM && !withSwagger && !withEcode {
withBM = true
withGRPC = true
@ -37,7 +41,7 @@ func protocAction(ctx *cli.Context) (err error) {
if err = installBMGen(); err != nil {
return
}
if err = genBM(ctx); err != nil {
if err = genBM(files); err != nil {
return
}
}
@ -45,7 +49,7 @@ func protocAction(ctx *cli.Context) (err error) {
if err = installGRPCGen(); err != nil {
return err
}
if err = genGRPC(ctx); err != nil {
if err = genGRPC(files); err != nil {
return
}
}
@ -53,7 +57,7 @@ func protocAction(ctx *cli.Context) (err error) {
if err = installSwaggerGen(); err != nil {
return
}
if err = genSwagger(ctx); err != nil {
if err = genSwagger(files); err != nil {
return
}
}
@ -61,11 +65,11 @@ func protocAction(ctx *cli.Context) (err error) {
if err = installEcodeGen(); err != nil {
return
}
if err = genEcode(ctx); err != nil {
if err = genEcode(files); err != nil {
return
}
}
log.Printf("generate %v success.\n", ctx.Args())
log.Printf("generate %s success.\n", strings.Join(files, " "))
return nil
}
@ -95,7 +99,7 @@ func checkProtoc() error {
return nil
}
func generate(ctx *cli.Context, protoc string) error {
func generate(protoc string, files []string) error {
pwd, _ := os.Getwd()
gosrc := path.Join(gopath(), "src")
ext, err := latestKratos()
@ -103,9 +107,9 @@ func generate(ctx *cli.Context, protoc string) error {
return err
}
line := fmt.Sprintf(protoc, gosrc, ext, pwd)
log.Println(line, strings.Join(ctx.Args(), " "))
log.Println(line, strings.Join(files, " "))
args := strings.Split(line, " ")
args = append(args, ctx.Args()...)
args = append(args, files...)
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = pwd
cmd.Env = os.Environ()

@ -2,8 +2,6 @@ package main
import (
"os/exec"
"github.com/urfave/cli"
)
const (
@ -20,6 +18,6 @@ func installSwaggerGen() error {
return nil
}
func genSwagger(ctx *cli.Context) error {
return generate(ctx, _swaggerProtoc)
func genSwagger(files []string) error {
return generate(_swaggerProtoc, files)
}

Loading…
Cancel
Save