Skip to content

Commit 0b9b592

Browse files
committed
add supress
1 parent 64bb42f commit 0b9b592

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# goplater
22

3-
A Go utility to template files (also recursively)
3+
Goplater is a commandline programm that templates files by using local and also remote files.
44

5-
{{ @://https://raw.githubusercontent.com/CodeShellDev/secured-signal-api/refs/heads/main/docker-compose.yaml }}
5+
## Getting Started

cmd/root.go

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

9+
10+
var verbose bool
11+
var supress bool
12+
913
var rootCmd = &cobra.Command{
1014
Use: "goplater",
1115
Short: "Go Template CLI",
@@ -23,5 +27,6 @@ func Execute() {
2327
}
2428

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

cmd/template.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var sourceContext string = "."
2424
var whitespace []string
2525
var match []string
2626

27-
var verbose bool
2827
var recursive bool
2928
var flatten bool
3029

@@ -60,7 +59,6 @@ func init() {
6059
rootCmd.AddCommand(templateCmd)
6160

6261
templateCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "recusively template files")
63-
templateCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "print additional information")
6462
templateCmd.Flags().BoolVarP(&flatten, "flatten", "f", false, "flatten output path: don't preserve source folder structure")
6563

6664
templateCmd.Flags().StringVarP(&outputContext, "output", "o", ".", "output path for templated files")
@@ -263,6 +261,10 @@ func templateStr(str string, context TemplateContext, variables map[string]any)
263261
},
264262
})
265263

264+
if supress {
265+
templt = templating.AddTemplateOption(templt, "missingkey=zero")
266+
}
267+
266268
tmplStr, err = templating.ParseTemplate(templt, tmplStr, variables)
267269

268270
if err != nil {

utils/templating/templating.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ 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 {
30+
return templt.Option(options...)
31+
}
32+
2933
func TransformTemplateKeys(tmplStr string, prefix string, transform func(varRegex *regexp.Regexp, m string) string) (string, error) {
3034
re, err := regexp.Compile(`{{[^{}]+}}`)
3135

0 commit comments

Comments
 (0)