feat(*): support perComandTimeout & variables in options

Signed-off-by: storyicon <yuanchao@bilibili.com>
This commit is contained in:
storyicon 2021-08-28 14:36:47 +08:00
parent 7b2c0762d4
commit 15047711a9
No known key found for this signature in database
GPG key ID: 245915D985F966CF
15 changed files with 302 additions and 122 deletions

View file

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

View file

@ -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 {