support *.proto

pull/398/head
小旭 5 years ago
parent e14170de04
commit c7d4742b01
  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 ( import (
"os/exec" "os/exec"
"github.com/urfave/cli"
) )
const ( const (
@ -20,6 +18,6 @@ func installBMGen() error {
return nil return nil
} }
func genBM(ctx *cli.Context) error { func genBM(files []string) error {
return generate(ctx, _bmProtoc) return generate(_bmProtoc, files)
} }

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

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

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

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

Loading…
Cancel
Save