Skip to content

TemplateCache: 'customs' should allow missing keys #536

@abhinav

Description

@abhinav

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions