gruntwork-io / boilerplate

A tool for generating files and folders ("boilerplate") from a set of templates
https://www.gruntwork.io
183 stars 16 forks source link

Support a configurable missing key action #6

Closed brikis98 closed 8 years ago

brikis98 commented 8 years ago

This PR adds a new flag to boilerplate called missing-key-action. This flag determines what boilerplate will do if a template references a variable that is not defined:

brikis98 commented 8 years ago

@josh-padnick This is ready for review

josh-padnick commented 8 years ago

I haven't reviewed the code yet, but at first blush, invalid seems like the wrong word to return a placeholder. "Invalid" makes me think that if something isn't valid, an error should be thrown. Otherwise, we're just marking something explicitly as empty. So I vote to use the word placeholder instead.

josh-padnick commented 8 years ago

Left minor comments but overall LGTM! Feel free to respond as desired and merge.

brikis98 commented 8 years ago

I haven't reviewed the code yet, but at first blush, invalid seems like the wrong word to return a placeholder. "Invalid" makes me think that if something isn't valid, an error should be thrown. Otherwise, we're just marking something explicitly as empty. So I vote to use the word placeholder instead.

It's based on the names of the settings supported by Go's templating system:

"missingkey=default" or "missingkey=invalid"
    The default behavior: Do nothing and continue execution.
    If printed, the result of the index operation is the string
    "<no value>".
"missingkey=zero"
    The operation returns the zero value for the map type's element.
"missingkey=error"
    Execution stops immediately with an error.
brikis98 commented 8 years ago

Merging now!