diff --git a/external/completion/completion.go b/external/completion/completion.go index 0b7ef56..f8ff911 100644 --- a/external/completion/completion.go +++ b/external/completion/completion.go @@ -294,6 +294,7 @@ func Complete(c Request) ([]string, cobra.ShellCompDirective) { } results = append(results, supportedFileTypes...) } + } } } diff --git a/external/json/to_json.go b/external/json/to_json.go index 30fc8f0..84873c5 100644 --- a/external/json/to_json.go +++ b/external/json/to_json.go @@ -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" @@ -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": diff --git a/external/templates/template.go b/external/templates/template.go new file mode 100644 index 0000000..fd31ecf --- /dev/null +++ b/external/templates/template.go @@ -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) + 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) + return templateString + } + + return renderedTpl.String() +}