-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Pull in sprig functions? #283
Comments
@docwhat weird coincidence - I was just thinking about that yesterday 😂... There's definitely some overlap, there's lots of things in Sprig that aren't yet in gomplate. Unfortunately the functions themselves aren't exported, so really we'd just be talking about copying the same functions into gomplate. An option would be to use the FuncMap that Sprig exports, and simply add that into the chain, but I'm not a big fan of that since it "pollutes" the root namespace. Basically, I think the right approach would be to be more methodical and bring in the specific functions that are missing, within the appropriate namespace. Or if the Sprig maintainers could be convinced to export all of the functions 🤔... |
Can't you just walk I didn't know if you knew that PS: |
😂 |
That's a really good point - hadn't considered that! I'll take a look to see how elegant (or inelegant) this can be.
Yup! |
So... Pretty inelegant, it turns out. With the exception of the (mostly legacy) functions in the root namespace, the only entries in gomplate's main FuncMap are namespaces like If I wanted to add the // Abbrev -
func (f *StringFuncs) Abbrev(width int, s string) (string, error) {
a := sprig.GenericFuncMap()["abbrev"]
switch v := a.(type) {
case func(int, string) string:
return v(width, s), nil
default:
panic("wat")
}
} TBH, this is more trouble than it's worth - especially (in this case) as there's actually an exported So I think instead of trying to shoehorn Thanks for logging the issue though. This is a good source of ideas for new functions! |
would not be overly difficult to import the sprig functions as sprig_* not properly namespaced, but not as bad as how they are doing it by default package funcs
import (
"github.com/Masterminds/sprig"
"fmt"
)
func AddSprigFuncs(f map[string]interface{}) {
for fn, fc := range sprig.TxtFuncMap() {
f[fmt.Sprintf("sprig_%s", fn)] = fc
}
} |
@djgilcrease true, but IMO it's a bit messy, and doesn't really fit in with the "feel" of the current gomplate functions. Are there any particular functions that you're missing? |
No, I was just commenting on the open task if someone absolutely needed it. I like your method of namespacing the template funcs, might be interesting to split it out into it's own project |
Ok, I'm going to close this issue out then. If there's any specific new functions that anyone needs - please open a new issue 🙂 |
Not looking to reopen this issue, but the big Sprig function that would be really nice to have access to is I am sure that there are probably a couple more that might be useful, but that is the biggie that I see. |
@hickey have you seen https://docs.gomplate.ca/functions/conv/#conv-default? (also please open a new issue if you're looking for new functions, or start a discussion) |
Ah, no I have not seen that. I would not have thought that the function would have been classified as a conversion method. Thanks for the pointer. |
Sprig looks like it has a lot of really cool functions. What about
stealingusing their library of functions in gomplate?The text was updated successfully, but these errors were encountered: