mirror of
https://github.com/TECHNOFAB11/powerproto.git
synced 2025-12-12 08:00:04 +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
|
|
@ -31,9 +31,10 @@ const (
|
|||
KeyNamePowerProtocInclude = "POWERPROTO_INCLUDE"
|
||||
// The default include can be referenced by this key in import paths
|
||||
KeyPowerProtoInclude = "$" + KeyNamePowerProtocInclude
|
||||
KeyNameSourceRelative = "SOURCE_RELATIVE"
|
||||
// KeySourceRelative can be specified in import paths to refer to
|
||||
// the folder where the current proto file is located
|
||||
KeySourceRelative = "$SOURCE_RELATIVE"
|
||||
KeySourceRelative = "$" + KeyNameSourceRelative
|
||||
// Defines the program directory of PowerProto, including various binary and include files
|
||||
EnvHomeDir = "POWERPROTO_HOME"
|
||||
// ProtobufRepository defines the protobuf repository
|
||||
|
|
|
|||
|
|
@ -16,12 +16,31 @@ package consts
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type debugMode struct{}
|
||||
type dryRun struct{}
|
||||
type ignoreDryRun struct{}
|
||||
type disableAction struct{}
|
||||
type perCommandTimeout struct{}
|
||||
|
||||
func GetContextWithPerCommandTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||
val := ctx.Value(perCommandTimeout{})
|
||||
if val == nil {
|
||||
return ctx, func() {}
|
||||
}
|
||||
duration, ok := val.(time.Duration)
|
||||
if !ok {
|
||||
return ctx, func() {}
|
||||
}
|
||||
return context.WithTimeout(ctx, duration)
|
||||
}
|
||||
|
||||
// WithPerCommandTimeout is used to inject per command timeout
|
||||
func WithPerCommandTimeout(ctx context.Context, timeout time.Duration) context.Context {
|
||||
return context.WithValue(ctx, perCommandTimeout{}, timeout)
|
||||
}
|
||||
|
||||
// WithDebugMode is used to set debug mode
|
||||
func WithDebugMode(ctx context.Context) context.Context {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue