Skip to content

Commit

Permalink
Parse all template files before executing
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Sep 26, 2023
1 parent 1733b42 commit f57fb5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/cli/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ func runExecute(cmd *cobra.Command, opts executeOptions) {
return
}

var re *recipe.Recipe
var err error
var wasRemoteRecipe bool
var (
re *recipe.Recipe
err error
wasRemoteRecipe bool
)

if strings.HasPrefix(opts.RecipeURL, "oci://") {
wasRemoteRecipe = true
ctx := context.Background()
Expand Down
4 changes: 4 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ func (e Engine) Render(templates map[string][]byte, values map[string]interface{

rendered := make(map[string][]byte)

// Parse all templates first
for name, data := range templates {
_, err := t.New(name).Parse(string(data))
if err != nil {
// TODO: Inner error message includes prefix "template: ", which does not good when printing this error
return nil, fmt.Errorf("failed to parse template: %w", err)
}
}

// Execute each template seperately
for name := range templates {
var buf strings.Builder
if err := t.ExecuteTemplate(&buf, name, values); err != nil {
// TODO: Inner error message includes prefix "template: ", which does not good when printing this error
Expand Down

0 comments on commit f57fb5f

Please sign in to comment.