add go-grpc_opt and go_opt for grpc new command (#1769)
Co-authored-by: zhouyy <zhouyy@ickey.cn>
This commit is contained in:
@@ -538,6 +538,14 @@ var commands = []cli.Command{
|
|||||||
Usage: `generate rpc demo service`,
|
Usage: `generate rpc demo service`,
|
||||||
UsageText: "example: goctl rpc new [options] service-name",
|
UsageText: "example: goctl rpc new [options] service-name",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "go_opt",
|
||||||
|
Hidden: true,
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "go-grpc_opt",
|
||||||
|
Hidden: true,
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "style",
|
Name: "style",
|
||||||
Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
|
Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/generator"
|
"github.com/zeromicro/go-zero/tools/goctl/rpc/generator"
|
||||||
@@ -58,6 +59,17 @@ func RPCNew(c *cli.Context) error {
|
|||||||
ctx.IsGooglePlugin = true
|
ctx.IsGooglePlugin = true
|
||||||
ctx.Output = filepath.Dir(src)
|
ctx.Output = filepath.Dir(src)
|
||||||
ctx.ProtocCmd = fmt.Sprintf("protoc -I=%s %s --go_out=%s --go-grpc_out=%s", filepath.Dir(src), filepath.Base(src), filepath.Dir(src), filepath.Dir(src))
|
ctx.ProtocCmd = fmt.Sprintf("protoc -I=%s %s --go_out=%s --go-grpc_out=%s", filepath.Dir(src), filepath.Base(src), filepath.Dir(src), filepath.Dir(src))
|
||||||
|
|
||||||
|
grpcOptList := c.StringSlice("go-grpc_opt")
|
||||||
|
if len(grpcOptList) > 0 {
|
||||||
|
ctx.ProtocCmd += " --go-grpc_opt=" + strings.Join(grpcOptList, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
goOptList := c.StringSlice("go_opt")
|
||||||
|
if len(goOptList) > 0 {
|
||||||
|
ctx.ProtocCmd += " --go_opt=" + strings.Join(goOptList, ",")
|
||||||
|
}
|
||||||
|
|
||||||
g := generator.NewGenerator(style, verbose)
|
g := generator.NewGenerator(style, verbose)
|
||||||
return g.Generate(&ctx)
|
return g.Generate(&ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user