pulumi/pkg/compiler/context.go
joeduffy b408c3ce2a Pass compiler options to template evaluation
In some cases, we want to specialize template generation based on
the options passed to the compiler.  This change flows them through
so that they can be accessed as

        {{if .Options.SomeSetting}}
        ...
        {{end}}
2016-12-09 12:42:28 -08:00

50 lines
1.4 KiB
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package compiler
import (
"github.com/marapongo/mu/pkg/ast"
"github.com/marapongo/mu/pkg/compiler/backends"
"github.com/marapongo/mu/pkg/util"
)
// Context holds all state available to any templates or code evaluated at compile-time.
type Context struct {
Options *Options // compiler options supplied.
Cluster *ast.Cluster // the cluster that we will deploy to.
Arch backends.Arch // the target cloud architecture.
Properties ast.PropertyBag // properties supplied at stack construction time.
}
// NewContext returns a new, empty context.
func NewContext(opts *Options) *Context {
return &Context{
Options: opts,
Properties: make(ast.PropertyBag),
}
}
// WithClusterArch returns a clone of this Context with the given cluster and architecture attached to it.
func (c *Context) WithClusterArch(cl *ast.Cluster, a backends.Arch) *Context {
util.Assert(cl != nil)
return &Context{
Cluster: cl,
Arch: a,
Options: c.Options,
Properties: c.Properties,
}
}
// WithProps returns a clone of this Context with the given properties attached to it.
func (c *Context) WithProps(props ast.PropertyBag) *Context {
if props == nil {
props = make(ast.PropertyBag)
}
return &Context{
Cluster: c.Cluster,
Arch: c.Arch,
Options: c.Options,
Properties: props,
}
}