mirror of
https://github.com/TECHNOFAB11/powerproto.git
synced 2025-12-12 16:10:03 +01:00
feat(*): dryRun/debug mode/mode plugins/googleapis
Signed-off-by: storyicon <yuanchao@bilibili.com>
This commit is contained in:
parent
9aac714c32
commit
da77c8086d
26 changed files with 730 additions and 126 deletions
33
cmd/powerproto/powerproto.yaml
Normal file
33
cmd/powerproto/powerproto.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
scopes:
|
||||
- ./
|
||||
googleapis: 75e9812478607db997376ccea247dd6928f70f45
|
||||
protoc: v3.17.3
|
||||
protocWorkDir: ""
|
||||
plugins:
|
||||
protoc-gen-deepcopy: istio.io/tools/cmd/protoc-gen-deepcopy@v0.0.0-20210720210831-58ecc8fccb3e
|
||||
protoc-gen-go: google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
|
||||
protoc-gen-go-grpc: google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
|
||||
protoc-gen-go-json: github.com/mitchellh/protoc-gen-go-json@v1.0.0
|
||||
protoc-gen-gofast: github.com/gogo/protobuf/protoc-gen-gofast@v1.3.2
|
||||
protoc-gen-gogo: github.com/gogo/protobuf/protoc-gen-gogo@v1.3.2
|
||||
protoc-gen-grpc-gateway: github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.5.0
|
||||
protoc-gen-openapiv2: github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.5.0
|
||||
options:
|
||||
- --go_out=.
|
||||
- --go_opt=paths=source_relative
|
||||
- --go-grpc_out=.
|
||||
- --go-grpc_opt=paths=source_relative
|
||||
- --grpc-gateway_out=.
|
||||
- --openapiv2_out=.
|
||||
- --gogo_out=.
|
||||
- --gofast_out=.
|
||||
- --deepcopy_out=source_relative:.
|
||||
- --go-json_out=.
|
||||
importPaths:
|
||||
- .
|
||||
- $GOPATH
|
||||
- $POWERPROTO_INCLUDE
|
||||
- $POWERPROTO_GOOGLEAPIS
|
||||
- $SOURCE_RELATIVE
|
||||
postActions: []
|
||||
postShell: ""
|
||||
|
|
@ -22,8 +22,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/storyicon/powerproto/pkg/bootstraps"
|
||||
"github.com/storyicon/powerproto/pkg/consts"
|
||||
"github.com/storyicon/powerproto/pkg/util"
|
||||
"github.com/storyicon/powerproto/pkg/util/command"
|
||||
"github.com/storyicon/powerproto/pkg/util/logger"
|
||||
)
|
||||
|
||||
|
|
@ -48,8 +48,8 @@ compile proto files and execute the post actions/shells:
|
|||
// powerproto build xxxxx.proto
|
||||
func CommandBuild(log logger.Logger) *cobra.Command {
|
||||
var recursive bool
|
||||
// todo: this feature is still under development
|
||||
var dryRun bool
|
||||
var debugMode bool
|
||||
var postScriptEnabled bool
|
||||
cmd := &cobra.Command{
|
||||
Use: "build [dir|proto file]",
|
||||
|
|
@ -59,10 +59,15 @@ func CommandBuild(log logger.Logger) *cobra.Command {
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := cmd.Context()
|
||||
if dryRun {
|
||||
ctx = command.WithDryRun(ctx)
|
||||
ctx = consts.WithDryRun(ctx)
|
||||
log.LogWarn(nil, "running in dryRun mode")
|
||||
}
|
||||
if !postScriptEnabled {
|
||||
ctx = command.WithDisableAction(ctx)
|
||||
ctx = consts.WithDisableAction(ctx)
|
||||
}
|
||||
if debugMode {
|
||||
ctx = consts.WithDebugMode(ctx)
|
||||
log.LogWarn(nil, "running in debug mode")
|
||||
}
|
||||
|
||||
target, err := filepath.Abs(args[0])
|
||||
|
|
@ -113,5 +118,7 @@ func CommandBuild(log logger.Logger) *cobra.Command {
|
|||
flags := cmd.PersistentFlags()
|
||||
flags.BoolVarP(&recursive, "recursive", "r", recursive, "whether to recursively traverse all child folders")
|
||||
flags.BoolVarP(&postScriptEnabled, "postScriptEnabled", "p", postScriptEnabled, "when this flag is attached, it will allow the execution of postActions and postShell")
|
||||
flags.BoolVarP(&debugMode, "debug", "d", debugMode, "debug mode")
|
||||
flags.BoolVarP(&dryRun, "dryRun", "y", dryRun, "dryRun mode")
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ func GetDefaultConfig() *configs.Config {
|
|||
Scopes: []string{
|
||||
"./",
|
||||
},
|
||||
Protoc: "latest",
|
||||
Protoc: "latest",
|
||||
GoogleAPIs: "75e9812478607db997376ccea247dd6928f70f45",
|
||||
Plugins: map[string]string{
|
||||
"protoc-gen-go": "google.golang.org/protobuf/cmd/protoc-gen-go@latest",
|
||||
"protoc-gen-go-grpc": "google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest",
|
||||
|
|
@ -64,7 +65,9 @@ func GetDefaultConfig() *configs.Config {
|
|||
ImportPaths: []string{
|
||||
".",
|
||||
"$GOPATH",
|
||||
"$POWERPROTO_INCLUDE",
|
||||
consts.KeyPowerProtoInclude,
|
||||
consts.KeyPowerProtoGoogleAPIs,
|
||||
consts.KeySourceRelative,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,27 @@ func GetWellKnownPlugins() []*Plugin {
|
|||
"--grpc-gateway_out=.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "protoc-gen-openapiv2",
|
||||
Pkg: "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest",
|
||||
Options: []string{
|
||||
"--openapiv2_out=.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "protoc-gen-gogo",
|
||||
Pkg: "github.com/gogo/protobuf/protoc-gen-gogo@latest",
|
||||
Options: []string{
|
||||
"--gogo_out=.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "protoc-gen-gofast",
|
||||
Pkg: "github.com/gogo/protobuf/protoc-gen-gofast@latest",
|
||||
Options: []string{
|
||||
"--gofast_out=.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "protoc-gen-deepcopy",
|
||||
Pkg: "istio.io/tools/cmd/protoc-gen-deepcopy@latest",
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/storyicon/powerproto/pkg/bootstraps"
|
||||
"github.com/storyicon/powerproto/pkg/component/pluginmanager"
|
||||
"github.com/storyicon/powerproto/pkg/configs"
|
||||
"github.com/storyicon/powerproto/pkg/consts"
|
||||
"github.com/storyicon/powerproto/pkg/util"
|
||||
"github.com/storyicon/powerproto/pkg/util/logger"
|
||||
"github.com/storyicon/powerproto/pkg/util/progressbar"
|
||||
|
|
@ -32,7 +33,7 @@ import (
|
|||
func tidy(ctx context.Context,
|
||||
pluginManager pluginmanager.PluginManager,
|
||||
configFilePath string) error {
|
||||
progress := progressbar.GetProgressBar(1)
|
||||
progress := progressbar.GetProgressBar(ctx, 1)
|
||||
progress.SetPrefix("tidy config")
|
||||
err := bootstraps.StepTidyConfigFile(ctx, pluginManager, progress, configFilePath)
|
||||
if err != nil {
|
||||
|
|
@ -47,6 +48,9 @@ func tidy(ctx context.Context,
|
|||
if err := bootstraps.StepInstallProtoc(ctx, pluginManager, configItems); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := bootstraps.StepInstallGoogleAPIs(ctx, pluginManager, configItems); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := bootstraps.StepInstallPlugins(ctx, pluginManager, configItems); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -56,10 +60,17 @@ func tidy(ctx context.Context,
|
|||
// By default, clean the powerproto.yaml of the current directory and all parent directories
|
||||
// You can also explicitly specify the configuration file to clean up
|
||||
func CommandTidy(log logger.Logger) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
var debugMode bool
|
||||
cmd := &cobra.Command{
|
||||
Use: "tidy [config file]",
|
||||
Short: "tidy the config file. It will replace the version number and install the protoc and proto plugins that declared in the config file",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := cmd.Context()
|
||||
if debugMode {
|
||||
ctx = consts.WithDebugMode(ctx)
|
||||
log.LogWarn(nil, "running in debug mode")
|
||||
}
|
||||
|
||||
var targets []string
|
||||
if len(args) != 0 {
|
||||
for _, arg := range args {
|
||||
|
|
@ -90,7 +101,7 @@ func CommandTidy(log logger.Logger) *cobra.Command {
|
|||
continue
|
||||
}
|
||||
log.LogInfo(nil, "tidy %s", path)
|
||||
if err := tidy(cmd.Context(), pluginManager, path); err != nil {
|
||||
if err := tidy(ctx, pluginManager, path); err != nil {
|
||||
log.LogFatal(map[string]interface{}{
|
||||
"path": path,
|
||||
"err": err,
|
||||
|
|
@ -105,4 +116,7 @@ func CommandTidy(log logger.Logger) *cobra.Command {
|
|||
log.LogInfo(nil, "\r\nsucceeded, you are ready to go :)")
|
||||
},
|
||||
}
|
||||
flags := cmd.PersistentFlags()
|
||||
flags.BoolVarP(&debugMode, "debug", "d", debugMode, "debug mode")
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue