feat: parse templates in collection-type variables #1526
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1477
Fixes #1511
This PR overhauls the way templating works in Task. Instead of having methods on
templater.Template
, we now have package-level functions instead. This allows us to use generics (as generic methods aren't possible right now) which vastly simplifies the calling API. This is especially useful for the "Any Variables" experiment since many types of variable may need to support templating.For example, we now have the ability to support collection-type variables (slices/maps) and these might contain strings in which we want to use templates. See example below:
Running the above Taskfile in v3.35.0 or lower will result in the following:
Not that the
.does.not.work
variable contains a template, but it is not parsed. After this PR the result will work as expected:This is possible because any variable can now be passed into the
templater.Replace(...)
function and it will automatically traverse the value and find all strings that need replacing, whether they are raw strings, or nested strings inside a map/slice.It's worth mentioning that I have not actually removed the old
templater.Template
struct. It is now calledtemplater.Cache
(as this is its primary use) and it is passed in as a regular function parameter instead. It's possible that we could make changes to this too, but I figured I'd leave that for another day rather than trying to bundle a bunch of error handling changes in the same PR.