-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace github.com/masterminds/sprig template functions #2668
Comments
Perhaps we could also take the opportunity to implement a higher-order function (which would add to the As you know, there is the An The Maybe this could even be done dynamically with reflection? So we could do something like:
Separating the logic would remove the need for explicit functions in all but the most specialized cases, which would remove clutter and be trivial to extend as new functions are added. The alternative, which would be better, but also likely increase complexity, would be to add iteration logic to every requisite function, so that you can pass it a single item or a list of items and get the expected output, e.g.
This approach would be easier if we had control over how each function is implemented, as sprig is essentially a black box in this case. Likely v3 because this would mean removing/replacing/renaming Interested in any thoughts anyone might have. |
The tricky thing here is that |
Doesn't it just add function permutations to the I know it's probably not possible to do something like
but that is different, no? I tried dropping the example in the linked issue in to test but it's not compatible without some tweaks ( Are you saying it's impossible to do something like funcMap["squoteEach"] = each(squote)
funcMap["add1Each"] = each(add1) without a Making all template functions list-aware somehow is probably more user friendly anyway, but I'm not sure exactly what that implementation would look like. Should we create a |
Ah, sorry I misunderstood. My misunderstanding was that I thought that If I now I understand correctly, I have to ask, though: given that |
Note it's also possible to extend template functions so that they operate on lists as well as isolated values. For example, we can extend
Hmm, yes. I'll create a |
I think we should just do this. I'd argue that |
So, sadly, thanks to Masterminds/sprig's inherent brokenness, this isn't as immediately fixable as I had hoped. Some specific problems:
So, replacing the template library is definitely something for chezmoi v3, as trying to maintain backwards compatibility with all of Minorminds stupidity is just not possible. |
Also, just to clarify as I didn't do it before...
You're absolutely right, especially if the solution was to add
|
https://github.com/chezmoi/templatefuncs contains some initial replacement template functions. It's a work in progress. |
I asked on golang-nuts if there are existing alternatives to Minorminds/sprig. |
I was looking at gomplate the other day and it seems to me that it has a few nice things about it and may be a viable replacement for sprig in a number of places; it has other features that aren't as applicable to Chezmoi (but many of them would be, I think). The biggest thing that I liked about it is that it exposes objects rather than functions (although some functions are common enough to expose aliases), so for v3 (#2673) it would be possible to have |
@halostatue I'd personally rather take inspiration from gomplate than integrate it into chezmoi. If gomplate went the way of sprig, we would just find ourselves in this situation again. Creating our own bespoke function library allows us to fix and extend things quickly, rather than having to patch in our own fixes and create discrepancies like the one mentioned recently in #3335:
Using objects just isn't necessary for some use cases. Would we really benefit from having something like |
For some operations, sure having both the alias and the full version would be a waste. On the other hand, collecting password manager functionality into objects with functions available would IMO be much cleaner. Providing migration steps for this would be vital (e.g., reimplement the 1Password functionality as The warning phase could even be done as "light" (the use of a deprecated function/alias warns once) and "heavy" (each use of a deprecated function/alias warns). This sort of approach would allow us to think about what functions should be quickly available ( I may put together a list of the functions available in chezmoi via sprig or direct and suggest some sort of organization. |
Generally I agree, but I think we need to get https://github.com/chezmoi/templatefuncs in a much more complete state before we even think about that. I think v3 should be a clean break, and we should be as noisy as would be reasonable about that leading up to its release (once the new features are nearing completion). |
So, I propose to make this change in an incremental way, without needing chezmoi v3, with the following strategy:
This should allow an orderly transition from sprig to templatefuncs, and of course the user can use @bradenhilton thoughts? |
This seems like a reasonable approach to me. |
@twpayne How do you propose we handle the current chezmoi-specific functions, especially functions such as I do think incremental adoption is a good idea. |
Just came across this fork of sprig: https://github.com/go-sprout/sprout Here's an issue with some discussion on roadmap: go-sprout/sprout#1 I do not know if sprout aims to solve the problems raised in the first post of this issue. This is just a FYI :) |
Hi everyone, as currently the main maintainer of go-sprout/sprout, I wanted to provide some additional context and insights regarding your initial issue.
Firstly, I agree this is something we should address in order to improve compatibility.
Secondly, the naming convention of sprig does not match Go's, which could lead to confusion or issues when using the library. Giving a second life to sprig with sprout is an exciting challenge due to who use sprig (like Helm, tempo and Argo), we need to involve with backward-compatibility to don't break end-users configuration and go forward too. This is a complex issue, but I'm confident we can find a solution that balances both needs. If you have any questions or concerns, please don't hesitate to reach out on our discussions page (https://github.com/orgs/go-sprout/discussions) or ping me directly (@42atomys). Have a great day everyone! |
Is your feature request related to a problem? Please describe.
github.com/masterminds/sprig
, used by chezmoi, has unfortunately become a popular library of template functions despite several critical issues:toJson
should betoJSON
).Describe the solution you'd like
chezmoi's template functions should be up-to-date, compatible with Go template pipelining, and match Go's naming conventions.
Describe alternatives you've considered
Keeping minorminds/sprig template functions as-is.
Additional context
A smooth transition should be provided, with both old and replacement template functions being available to users for some time. Users can use
.chezmoiversion
to help the transition.The text was updated successfully, but these errors were encountered: