Skip to content

Commit

Permalink
return *yamlmeta.DocumentSet from EvalYAML explicitly instead of inte…
Browse files Browse the repository at this point in the history
…rface{}
  • Loading branch information
cppforlife committed Jul 2, 2019
1 parent 1b1b96c commit a744459
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions pkg/cmd/template/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ func (o *TemplateOptions) RunWithFiles(in TemplateInput, ui cmdcore.PlainUI) Tem
// TODO find more generic way
switch fileInLib.File.Type() {
case files.TypeYAML:
_, resultVal, err := loader.EvalYAML(fileInLib.Library, fileInLib.File)
_, resultDocSet, err := loader.EvalYAML(fileInLib.Library, fileInLib.File)
if err != nil {
return TemplateOutput{Err: err}
}

resultDocSet := resultVal.(*yamlmeta.DocumentSet)
outputDocSets[fileInLib] = resultDocSet

case files.TypeText:
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/template/data_values_pre_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ func (o DataValuesPreProcessing) Apply() (interface{}, error) {
}

func (p DataValuesPreProcessing) templateFile(fileInLib *workspace.FileInLibrary) ([]*yamlmeta.Document, error) {
_, resultVal, err := p.loader.EvalYAML(fileInLib.Library, fileInLib.File)
_, resultDocSet, err := p.loader.EvalYAML(fileInLib.Library, fileInLib.File)
if err != nil {
return nil, err
}

resultDocSet := resultVal.(*yamlmeta.DocumentSet)
tplOpts := yamltemplate.MetasOpts{IgnoreUnknown: p.IgnoreUnknownComments}

// Extract _all_ data values docs from the templated result
Expand Down
4 changes: 2 additions & 2 deletions pkg/workspace/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (l *TemplateLoader) LoadData(thread *starlark.Thread, f *starlark.Builtin,
return starlark.String(string(fileBs)), nil
}

func (l *TemplateLoader) EvalYAML(library *Library, file *files.File) (starlark.StringDict, interface{}, error) {
func (l *TemplateLoader) EvalYAML(library *Library, file *files.File) (starlark.StringDict, *yamlmeta.DocumentSet, error) {
fileBs, err := file.Bytes()
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -174,7 +174,7 @@ func (l *TemplateLoader) EvalYAML(library *Library, file *files.File) (starlark.
return nil, nil, err
}

return globals, resultVal, nil
return globals, resultVal.(*yamlmeta.DocumentSet), nil
}

func (l *TemplateLoader) EvalText(library *Library, file *files.File) (starlark.StringDict, *texttemplate.NodeRoot, error) {
Expand Down

0 comments on commit a744459

Please sign in to comment.