@@ -24,7 +24,8 @@ Options:
24
24
-e, --env-data Input data source comes from environment variables.
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
- --help PATH Display this help and exit.
27
+ -s, --strict Strict mode (causes an error if a key is missing)
28
+ --help Display this help and exit.
28
29
--version Output version information and exit.
29
30
30
31
INPUT defaults to standard input and OUTPUT defaults to standard output.
@@ -92,7 +93,7 @@ func main() {
92
93
93
94
var (
94
95
inputFile , outputFile , jsonDataFile , yamlDataFile string
95
- envFlag , helpFlag , versionFlag bool
96
+ envFlag , strictFlag , helpFlag , versionFlag bool
96
97
)
97
98
98
99
flag .StringVar (& inputFile , "input" , "" , "input template file in go template format" )
@@ -105,6 +106,8 @@ func main() {
105
106
flag .StringVar (& outputFile , "o" , "" , "write the output to the file at OUTPUT" )
106
107
flag .StringVar (& yamlDataFile , "yaml-data" , "" , "input data source in YAML format" )
107
108
flag .StringVar (& yamlDataFile , "y" , "" , "input data source in YAML format" )
109
+ flag .BoolVar (& strictFlag , "strict" , false , "strict mode (causes an error if a key is missing)" )
110
+ flag .BoolVar (& strictFlag , "s" , false , "strict mode (causes an error if a key is missing)" )
108
111
flag .BoolVar (& versionFlag , "version" , false , "output version information and exit" )
109
112
flag .BoolVar (& helpFlag , "help" , false , "display this help and exit" )
110
113
flag .Parse ()
@@ -157,7 +160,11 @@ func main() {
157
160
log .Fatalf ("Error opening data file: %v\n " , err )
158
161
}
159
162
// Parse Input
160
- tpl , err := template .New ("template" ).Parse (string (tplStr ))
163
+ missingkey := "default"
164
+ if strictFlag {
165
+ missingkey = "error"
166
+ }
167
+ tpl , err := template .New ("template" ).Option (fmt .Sprintf ("missingkey=%s" , missingkey )).Parse (string (tplStr ))
161
168
if err != nil {
162
169
log .Fatalf ("Error parsing template: %v\n " , err )
163
170
}
0 commit comments