Add verbose flag (#1696)
Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -23,6 +23,7 @@ func RPCNew(c *cli.Context) error {
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
verbose := c.Bool("verbose")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
@@ -52,7 +53,7 @@ func RPCNew(c *cli.Context) error {
|
||||
ctx.IsGooglePlugin = true
|
||||
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))
|
||||
g := generator.NewGenerator(style)
|
||||
g := generator.NewGenerator(style, verbose)
|
||||
return g.Generate(&ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ func ZRPC(c *cli.Context) error {
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
verbose := c.Bool("verbose")
|
||||
if len(grpcOutList) == 0 {
|
||||
return errInvalidGrpcOutput
|
||||
}
|
||||
@@ -107,7 +108,7 @@ func ZRPC(c *cli.Context) error {
|
||||
ctx.IsGooglePlugin = isGooglePlugin
|
||||
ctx.Output = zrpcOut
|
||||
ctx.ProtocCmd = strings.Join(protocArgs, " ")
|
||||
g := generator.NewGenerator(style)
|
||||
g := generator.NewGenerator(style, verbose)
|
||||
return g.Generate(&ctx)
|
||||
}
|
||||
|
||||
@@ -117,11 +118,13 @@ func removeGoctlFlag(args []string) []string {
|
||||
for step < len(args) {
|
||||
arg := args[step]
|
||||
switch {
|
||||
case arg == "--style", arg == "--home", arg == "--zrpc_out":
|
||||
case arg == "--style", arg == "--home", arg == "--zrpc_out", arg == "--verbose", arg == "-v":
|
||||
step += 2
|
||||
continue
|
||||
case strings.HasPrefix(arg, "--style="),
|
||||
strings.HasPrefix(arg, "--home="),
|
||||
strings.HasPrefix(arg, "--verbose="),
|
||||
strings.HasPrefix(arg, "-v="),
|
||||
strings.HasPrefix(arg, "--zrpc_out="):
|
||||
step += 1
|
||||
continue
|
||||
|
||||
@@ -10,25 +10,27 @@ import (
|
||||
|
||||
// Generator defines the environment needs of rpc service generation
|
||||
type Generator struct {
|
||||
log console.Console
|
||||
cfg *conf.Config
|
||||
log console.Console
|
||||
cfg *conf.Config
|
||||
verbose bool
|
||||
}
|
||||
|
||||
// NewGenerator returns an instance of Generator
|
||||
func NewGenerator(style string) *Generator {
|
||||
func NewGenerator(style string, verbose bool) *Generator {
|
||||
cfg, err := conf.NewConfig(style)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log := console.NewColorConsole()
|
||||
log := console.NewColorConsole(verbose)
|
||||
return &Generator{
|
||||
log: log,
|
||||
cfg: cfg,
|
||||
log: log,
|
||||
cfg: cfg,
|
||||
verbose: verbose,
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare provides environment detection generated by rpc service,
|
||||
// including go environment, protoc, whether protoc-gen-go is installed or not
|
||||
func (g *Generator) Prepare() error {
|
||||
return env.Prepare(true, true)
|
||||
return env.Prepare(true, true, g.verbose)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user