pulumi/pkg/engine/events.go
Joe Duffy f0c28db639
Attempt to fix colorization (#740)
Our recent changes to colorization changed from a boolean to a tri-valued
enum (Always, Never, Raw).  The events from the service, however, are still
boolean-valued.  This changes the message payload to carry the full values.
2017-12-18 11:42:32 -08:00

108 lines
2.1 KiB
Go

// Copyright 2017, Pulumi Corporation. All rights reserved.
package engine
import (
"fmt"
"github.com/pulumi/pulumi/pkg/diag"
"github.com/pulumi/pulumi/pkg/diag/colors"
)
// Event represents an event generated by the engine during an operation. The underlying
// type for the `Payload` field will differ depending on the value of the `Type` field
type Event struct {
Type EventType
Payload interface{}
}
// EventType is the kind of event being emitted.
type EventType string
const (
CancelEvent EventType = "cancel"
StdoutColorEvent EventType = "stdoutcolor"
DiagEvent EventType = "diag"
)
func cancelEvent() Event {
return Event{Type: CancelEvent}
}
// DiagEventPayload is the payload for an event with type `diag`
type DiagEventPayload struct {
Message string
Color colors.Colorization
Severity diag.Severity
}
type StdoutEventPayload struct {
Message string
Color colors.Colorization
}
func stdOutEventWithColor(s fmt.Stringer, color colors.Colorization) Event {
return Event{
Type: StdoutColorEvent,
Payload: StdoutEventPayload{
Message: s.String(),
Color: color,
},
}
}
func diagDebugEvent(msg string, color colors.Colorization) Event {
return Event{
Type: DiagEvent,
Payload: DiagEventPayload{
Message: msg,
Color: color,
Severity: diag.Debug,
},
}
}
func diagInfoEvent(msg string, color colors.Colorization) Event {
return Event{
Type: DiagEvent,
Payload: DiagEventPayload{
Message: msg,
Color: color,
Severity: diag.Info,
},
}
}
func diagInfoerrEvent(msg string, color colors.Colorization) Event {
return Event{
Type: DiagEvent,
Payload: DiagEventPayload{
Message: msg,
Color: color,
Severity: diag.Infoerr,
},
}
}
func diagErrorEvent(msg string, color colors.Colorization) Event {
return Event{
Type: DiagEvent,
Payload: DiagEventPayload{
Message: msg,
Color: color,
Severity: diag.Error,
},
}
}
func diagWarningEvent(msg string, color colors.Colorization) Event {
return Event{
Type: DiagEvent,
Payload: DiagEventPayload{
Message: msg,
Color: color,
Severity: diag.Warning,
},
}
}