forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpolate.go
44 lines (33 loc) · 977 Bytes
/
interpolate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"github.com/cppforlife/go-patch/patch"
. "github.com/cloudfoundry/bosh-cli/cmd/opts"
boshtpl "github.com/cloudfoundry/bosh-cli/director/template"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type InterpolateCmd struct {
ui boshui.UI
}
func NewInterpolateCmd(ui boshui.UI) InterpolateCmd {
return InterpolateCmd{ui: ui}
}
func (c InterpolateCmd) Run(opts InterpolateOpts) error {
tpl := boshtpl.NewTemplate(opts.Args.Manifest.Bytes)
vars := opts.VarFlags.AsVariables()
op := opts.OpsFlags.AsOp()
evalOpts := boshtpl.EvaluateOpts{
ExpectAllKeys: opts.VarErrors,
ExpectAllVarsUsed: opts.VarErrorsUnused,
}
if opts.Path.IsSet() {
evalOpts.PostVarSubstitutionOp = patch.FindOp{Path: opts.Path}
// Printing YAML indented multiline strings (eg SSH key) is not useful
evalOpts.UnescapedMultiline = true
}
bytes, err := tpl.Evaluate(vars, op, evalOpts)
if err != nil {
return err
}
c.ui.PrintBlock(bytes)
return nil
}