-
Notifications
You must be signed in to change notification settings - Fork 14
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
Enable all sprig functions in templates #59
Conversation
@@ -31,7 +31,7 @@ func NewGeneratorWithTextTemplate(tpl []byte, cfg Config, fields Fields) (*Gener | |||
|
|||
state := NewGenState() | |||
|
|||
templateFns := sprig.HermeticTxtFuncMap() | |||
templateFns := sprig.TxtFuncMap() | |||
|
|||
templateFns["timeDuration"] = func(duration int64) time.Duration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd would be nice if we can add timeDuration
directly to sprig in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can work in submitting this function to the library, but is not clear to me which is the expected usage. sprig
already provides dateModify
function, how would this be different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dateModify, mustDateModify
The dateModify takes a modification and a date and returns the timestamp.
it is unclear to me if it returns a time.Time
, what's exactly a "timestamp"? :)
we can test anyway, if so, no need, since we can have
{{- $durationInSecond := generate "durationInSecond" }}
{{- $durationString := cat $durationInSecond "s" | nospace }}
{{- $modifiedTime := $timeField | dateModify $durationString }}
{{ $modifiedTime.Format "2006-01-02T15:04:05.999999Z07:00" }}
otherwise we need a function to generate a time.Duration
from an int or string (I could not find any in sprig), since we don't have anything in the fields type that generates a time.Duration
(and we probably cannot have, since the type comes from package spec)
I think you need to merge main on the branch @endorama |
Non hermetic functions are defined as "impure" functions. The list is available here: https://github.com/Masterminds/sprig/blob/581758eb7d96ae4d113649668fa96acc74d46e7f/functions.go#L70 We enable them mainly due to date related functions that are very beneficial to template developers.
f96857f
to
17a3222
Compare
Non hermetic functions are defined as "impure" functions. The list is
available here: https://github.com/Masterminds/sprig/blob/581758eb7d96ae4d113649668fa96acc74d46e7f/functions.go#L70
We enable them mainly due to date related functions that are very
beneficial to template developers.