miniscruff/changie

TemplateCache: 'customs' should allow missing keys

Closed this issue · 1 comments

Is your feature request related to a problem? Please describe.

Currently, the customs template function will return an error if a requested key was missing for any of the changelog entries.
This makes it difficult to add a new custom key with existing unreleased changes.

For example, if you do:

changie init
changie new # answer prompts
changie new # answer prompts

$EDITOR .changie.yaml 
# Add a new custom config, and use it in the template with `{{customs .Changes "Foo"}}`.

changie batch
# Error: missing custom key: 'Foo'

Describe the solution you'd like
The customs function should return an empty string for keys that are absent.
This will match the behavior of directly accessing the custom field via .Change.Custom.Foo.

Alternatively, if this this change is considered breaking, a new function customValues would do.

Describe alternatives you've considered
Iterating over .Changes and accessing the custom fields directly.
This isn't as nice because you can't post-process and dedupe, e.g. customs .Changes "Foo" | compact | uniq.

Additional context
If we're in agreement about the change, I'm happy to make a PR for it.

Hmm, I think my idea for this at the time was that, it could prevent typos if you see an error over an empty string. But I agree it is a little lame thinking about it again. I agree with this change.