databricks-cli/libs/cmdio/context.go

21 lines
506 B
Go
Raw Normal View History

package cmdio
2023-03-29 12:58:09 +00:00
import (
"context"
)
type progressLogger int
var progressLoggerKey progressLogger
// NewContext returns a new Context that carries the specified progress logger.
func NewContext(ctx context.Context, logger *Logger) context.Context {
return context.WithValue(ctx, progressLoggerKey, logger)
}
// FromContext returns the progress logger value stored in ctx, if any.
func FromContext(ctx context.Context) (*Logger, bool) {
u, ok := ctx.Value(progressLoggerKey).(*Logger)
return u, ok
}