Skip to content

Commit 176174a

Browse files
committed
change delim from {{}} to {{{}}}
1 parent 9c7f099 commit 176174a

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

cmd/root.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
10-
var verbose bool
11-
var supress bool
12-
139
var rootCmd = &cobra.Command{
1410
Use: "goplater",
1511
Short: "Go Template CLI",
@@ -27,6 +23,5 @@ func Execute() {
2723
}
2824

2925
func init() {
30-
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "print additional information")
31-
rootCmd.Flags().BoolVarP(&supress, "ignore-errors", "i", false, "ignore / supress errors")
26+
3227
}

cmd/template.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var match []string
2727
var recursive bool
2828
var flatten bool
2929

30+
var verbose bool
31+
var supress bool
32+
3033
type TemplateContext struct {
3134
invoker string
3235
name string
@@ -67,6 +70,9 @@ func init() {
6770
templateCmd.Flags().StringSliceVarP(&match, "match", "m", []string{".*"}, "regex match for templating")
6871

6972
templateCmd.Flags().StringSliceVarP(&whitespace, "whitespace", "w", []string{"l","t"}, "remove whitespace from files")
73+
74+
templateCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "print additional information")
75+
templateCmd.Flags().BoolVarP(&supress, "ignore-errors", "i", false, "ignore / supress errors")
7076
}
7177

7278
func run(cmd *cobra.Command, args []string) {
@@ -157,6 +163,8 @@ func templateFile(relativePath string) error {
157163
}
158164

159165
func templateContent(content string, context TemplateContext) (string, error) {
166+
167+
160168
normalized := normalize(content)
161169

162170
tmplStr, err := templateStr(normalized, context, nil)
@@ -261,8 +269,10 @@ func templateStr(str string, context TemplateContext, variables map[string]any)
261269
},
262270
})
263271

272+
templt = templating.AddTemplateDelim(templt, "{{{", "}}}")
273+
264274
if supress {
265-
templt = templating.AddTemplateOption(templt, "missingkey=zero")
275+
templt = templating.AddTemplateOptions(templt, "missingkey=zero")
266276
}
267277

268278
tmplStr, err = templating.ParseTemplate(templt, tmplStr, variables)

utils/templating/templating.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ func CreateTemplateWithFunc(name string, funcMap template.FuncMap) *template.Tem
2626
return template.New(name).Funcs(funcMap)
2727
}
2828

29-
func AddTemplateOption(templt *template.Template, options ...string) *template.Template {
29+
func AddTemplateOptions(templt *template.Template, options ...string) *template.Template {
3030
return templt.Option(options...)
3131
}
3232

33+
func AddTemplateDelim(templt *template.Template, left, right string) *template.Template {
34+
return templt.Delims(left, right)
35+
}
36+
3337
func TransformTemplateKeys(tmplStr string, prefix string, transform func(varRegex *regexp.Regexp, m string) string) (string, error) {
3438
re, err := regexp.Compile(`{{[^{}]+}}`)
3539

0 commit comments

Comments
 (0)