mirror of
https://github.com/TECHNOFAB11/powerproto.git
synced 2025-12-14 08:53:48 +01:00
feat(*): support perComandTimeout & variables in options
Signed-off-by: storyicon <yuanchao@bilibili.com>
This commit is contained in:
parent
7b2c0762d4
commit
15047711a9
15 changed files with 302 additions and 122 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ func CommandBuild(log logger.Logger) *cobra.Command {
|
|||
var dryRun bool
|
||||
var debugMode bool
|
||||
var postScriptEnabled bool
|
||||
perCommandTimeout := time.Second * 300
|
||||
cmd := &cobra.Command{
|
||||
Use: "build [dir|proto file]",
|
||||
Short: "compile proto files",
|
||||
|
|
@ -59,6 +61,7 @@ func CommandBuild(log logger.Logger) *cobra.Command {
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.SetLogLevel(logger.LevelInfo)
|
||||
ctx := cmd.Context()
|
||||
ctx = consts.WithPerCommandTimeout(ctx, perCommandTimeout)
|
||||
if debugMode {
|
||||
ctx = consts.WithDebugMode(ctx)
|
||||
log.LogWarn(nil, "running in debug mode")
|
||||
|
|
@ -122,5 +125,6 @@ func CommandBuild(log logger.Logger) *cobra.Command {
|
|||
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")
|
||||
flags.DurationVarP(&perCommandTimeout, "timeout", "t", perCommandTimeout, "execution timeout for per command")
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
|
@ -62,11 +63,13 @@ func tidy(ctx context.Context,
|
|||
// You can also explicitly specify the configuration file to clean up
|
||||
func CommandTidy(log logger.Logger) *cobra.Command {
|
||||
var debugMode bool
|
||||
perCommandTimeout := time.Second * 300
|
||||
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()
|
||||
ctx = consts.WithPerCommandTimeout(ctx, perCommandTimeout)
|
||||
log.SetLogLevel(logger.LevelInfo)
|
||||
if debugMode {
|
||||
log.SetLogLevel(logger.LevelDebug)
|
||||
|
|
@ -121,5 +124,6 @@ func CommandTidy(log logger.Logger) *cobra.Command {
|
|||
}
|
||||
flags := cmd.PersistentFlags()
|
||||
flags.BoolVarP(&debugMode, "debug", "d", debugMode, "debug mode")
|
||||
flags.DurationVarP(&perCommandTimeout, "timeout", "t", perCommandTimeout, "execution timeout for per command")
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue