From c7d4742b01e6427679b10dddd774092e84563b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=97=AD?= Date: Tue, 29 Oct 2019 00:20:44 +0800 Subject: [PATCH] support *.proto --- tool/kratos-protoc/bm.go | 8 +++----- tool/kratos-protoc/ecode.go | 6 ++---- tool/kratos-protoc/grpc.go | 6 ++---- tool/kratos-protoc/protoc.go | 20 ++++++++++++-------- tool/kratos-protoc/swagger.go | 6 ++---- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/tool/kratos-protoc/bm.go b/tool/kratos-protoc/bm.go index 2c6b4e13f..5f88e00dd 100644 --- a/tool/kratos-protoc/bm.go +++ b/tool/kratos-protoc/bm.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) +} \ No newline at end of file diff --git a/tool/kratos-protoc/ecode.go b/tool/kratos-protoc/ecode.go index 22966e121..48da9ca9f 100644 --- a/tool/kratos-protoc/ecode.go +++ b/tool/kratos-protoc/ecode.go @@ -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) } diff --git a/tool/kratos-protoc/grpc.go b/tool/kratos-protoc/grpc.go index b21da8dad..760f29574 100644 --- a/tool/kratos-protoc/grpc.go +++ b/tool/kratos-protoc/grpc.go @@ -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) } diff --git a/tool/kratos-protoc/protoc.go b/tool/kratos-protoc/protoc.go index 57b3bec19..ed2ba5f5c 100644 --- a/tool/kratos-protoc/protoc.go +++ b/tool/kratos-protoc/protoc.go @@ -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() diff --git a/tool/kratos-protoc/swagger.go b/tool/kratos-protoc/swagger.go index 7d1b61aaf..be89670a7 100644 --- a/tool/kratos-protoc/swagger.go +++ b/tool/kratos-protoc/swagger.go @@ -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) }