This refactors the engine so all of the APIs on it are instance methods on the type instead of raw methods that float around and use data from a global engine. A mechcanical change as we remove the global `E` and then make anything that interacted with that in pkg/engine to be an instance method and the dealing with the fallout.
32 lines
581 B
Go
32 lines
581 B
Go
package engine
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/pulumi/pulumi-fabric/pkg/diag"
|
|
"github.com/pulumi/pulumi-fabric/pkg/util/contract"
|
|
)
|
|
|
|
type Engine struct {
|
|
Stdout io.Writer
|
|
Stderr io.Writer
|
|
snk diag.Sink
|
|
}
|
|
|
|
func (e *Engine) Diag() diag.Sink {
|
|
if e.snk == nil {
|
|
e.InitDiag(diag.FormatOptions{})
|
|
}
|
|
|
|
return e.snk
|
|
}
|
|
|
|
func (e *Engine) InitDiag(opts diag.FormatOptions) {
|
|
contract.Assertf(e.snk == nil, "Cannot initialize diagnostics sink more than once")
|
|
|
|
// Force using our stdout and stderr
|
|
opts.Stdout = e.Stdout
|
|
opts.Stderr = e.Stderr
|
|
|
|
e.snk = diag.DefaultSink(opts)
|
|
}
|