add helm compatibility option

This commit is contained in:
Diego Fernando Carrión 2023-10-13 15:26:16 +02:00
parent 207aad94a0
commit 9d1f97258a
Signed by: CRThaze
GPG Key ID: 0F647F8A6A3AF588
2 changed files with 11 additions and 2 deletions

View File

@ -14,6 +14,8 @@ Usage of ./spry:
Output delimiter between template files rendered (default "---") Output delimiter between template files rendered (default "---")
-f value -f value
Specify a values file (JSON or YAML) Specify a values file (JSON or YAML)
-helm
Whether to nest provided values under .Values
-set value -set value
Set a specific value (foo.bar=spam) Set a specific value (foo.bar=spam)
``` ```

11
main.go
View File

@ -77,6 +77,7 @@ var flags struct {
valuesFiles valFileSlice valuesFiles valFileSlice
values valSlice values valSlice
outputDelimiter string outputDelimiter string
helmCompat bool
} }
func init() { func init() {
@ -87,6 +88,7 @@ func init() {
"d", "---", "d", "---",
"Output delimiter between template files rendered", "Output delimiter between template files rendered",
) )
flag.BoolVar(&flags.helmCompat, "helm", false, "Whether to nest provided values under .Values")
flag.Parse() flag.Parse()
} }
@ -164,8 +166,13 @@ func expandFiles(files []string) (expFiles []string) {
return return
} }
func mergeValues() (result map[string]interface{}) { func mergeValues() (res map[string]interface{}) {
result = map[string]interface{}{} res = map[string]interface{}{}
result := res
if flags.helmCompat {
res["Values"] = map[string]interface{}{}
result = res["Values"].(map[string]interface{})
}
for _, vf := range flags.valuesFiles { for _, vf := range flags.valuesFiles {
vfContent, err := os.ReadFile(vf) vfContent, err := os.ReadFile(vf)
checkErr(err) checkErr(err)