|
|
@ -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() |
|
|
|