Skip to content

Commit

Permalink
WIP #404
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west committed Mar 13, 2024
1 parent d07c691 commit df6897f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions external/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func Complete(c Request) ([]string, cobra.ShellCompDirective) {
}
results = append(results, supportedFileTypes...)
}

}
}
}
Expand Down
4 changes: 4 additions & 0 deletions external/json/to_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/elasticpath/epcc-cli/external/aliases"
"github.com/elasticpath/epcc-cli/external/resources"
"github.com/elasticpath/epcc-cli/external/templates"
"github.com/itchyny/gojq"
log "github.com/sirupsen/logrus"
"regexp"
Expand Down Expand Up @@ -53,6 +54,9 @@ func toJsonObject(args []string, noWrapping bool, compliant bool, attributes map
key := args[i]
val := args[i+1]

// Try and process the argument as a helm template
val = templates.Render(val)

jsonKey := key
switch {
case key == "type" || key == "id":
Expand Down
37 changes: 37 additions & 0 deletions external/templates/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package templates

import (
"bytes"
"github.com/Masterminds/sprig/v3"
log "github.com/sirupsen/logrus"
"strings"
"text/template"
)

func init() {

}
func Render(templateString string) string {

if !strings.Contains(templateString, "{{") {
return templateString
}

tpl, err := template.New("templateName").Funcs(sprig.FuncMap()).Parse(templateString)

if err != nil {
log.Warn("Could not process argument template: %s, due to %v", templateString, err)

Check failure on line 23 in external/templates/template.go

View workflow job for this annotation

GitHub Actions / Build

github.com/sirupsen/logrus.Warn call has possible Printf formatting directive %s
return templateString
}

var renderedTpl bytes.Buffer

err = tpl.Execute(&renderedTpl, nil)

if err != nil {
log.Warn("Could not process argument template: %s, due to %v", templateString, err)

Check failure on line 32 in external/templates/template.go

View workflow job for this annotation

GitHub Actions / Build

github.com/sirupsen/logrus.Warn call has possible Printf formatting directive %s
return templateString
}

return renderedTpl.String()
}

0 comments on commit df6897f

Please sign in to comment.