@@ -25,6 +25,7 @@ Options:
25
25
-i, --input INPUT Input template file in go template format.
26
26
-o, --output OUTPUT Write the output to the file at OUTPUT.
27
27
-s, --strict Strict mode (causes an error if a key is missing)
28
+ -d, --delimiters Set the delimiters used in the templates in the format <left>:<right> (default: '{{:}}')
28
29
--help Display this help and exit.
29
30
--version Output version information and exit.
30
31
@@ -33,7 +34,8 @@ INPUT defaults to standard input and OUTPUT defaults to standard output.
33
34
Examples:
34
35
$ datasubst --input examples/basic-input.txt --json-data examples/basic-data.json
35
36
$ echo "v3: {{ .key2.first.key3 }}" | datasubst --yaml-data examples/basic-data.yaml
36
- $ TEST1="hello" TEST2="world" datasubst --input examples/basic-input-env.txt --env-data`
37
+ $ echo "{{ .TEST1 }} {{ .TEST2 }}" | TEST1="hello" TEST2="world" datasubst --env-data
38
+ $ echo "(( .TEST ))" | TEST="hi" datasubst --env-data -d '((:))'`
37
39
38
40
var Version string
39
41
@@ -92,8 +94,8 @@ func main() {
92
94
}
93
95
94
96
var (
95
- inputFile , outputFile , jsonDataFile , yamlDataFile string
96
- envFlag , strictFlag , helpFlag , versionFlag bool
97
+ inputFile , outputFile , jsonDataFile , yamlDataFile , delimiters string
98
+ envFlag , strictFlag , helpFlag , versionFlag bool
97
99
)
98
100
99
101
flag .StringVar (& inputFile , "input" , "" , "input template file in go template format" )
@@ -106,6 +108,8 @@ func main() {
106
108
flag .StringVar (& outputFile , "o" , "" , "write the output to the file at OUTPUT" )
107
109
flag .StringVar (& yamlDataFile , "yaml-data" , "" , "input data source in YAML format" )
108
110
flag .StringVar (& yamlDataFile , "y" , "" , "input data source in YAML format" )
111
+ flag .StringVar (& delimiters , "delimiters" , "" , "Set the delimiters used in the templates in the format <left>:<right> (default: '{{:}}')" )
112
+ flag .StringVar (& delimiters , "d" , "" , "Set the delimiters used in the templates in the format <left>:<right> (default: '{{:}}')" )
109
113
flag .BoolVar (& strictFlag , "strict" , false , "strict mode (causes an error if a key is missing)" )
110
114
flag .BoolVar (& strictFlag , "s" , false , "strict mode (causes an error if a key is missing)" )
111
115
flag .BoolVar (& versionFlag , "version" , false , "output version information and exit" )
@@ -159,12 +163,18 @@ func main() {
159
163
if err != nil {
160
164
log .Fatalf ("Error opening data file: %v\n " , err )
161
165
}
162
- // Parse Input
163
- missingkey := "default"
166
+ tpl := template .New ("template" )
164
167
if strictFlag {
165
- missingkey = " error"
168
+ tpl . Option ( " missingkey= error")
166
169
}
167
- tpl , err := template .New ("template" ).Option (fmt .Sprintf ("missingkey=%s" , missingkey )).Parse (string (tplStr ))
170
+ if delimiters != "" {
171
+ if strings .Count (delimiters , ":" ) != 1 || delimiters [len (delimiters )- 1 :] == ":" || delimiters [0 :1 ] == ":" {
172
+ log .Fatal ("Error: invalid delimiter format. Must be '<left>:<right>' and ':'" )
173
+ }
174
+ d := strings .Split (delimiters , ":" )
175
+ tpl .Delims (d [0 ], d [1 ])
176
+ }
177
+ tpl , err = tpl .Parse (string (tplStr ))
168
178
if err != nil {
169
179
log .Fatalf ("Error parsing template: %v\n " , err )
170
180
}
0 commit comments