Integrate sprig for more helpers

This commit is contained in:
Thomas Boerger 2019-02-19 10:04:44 +01:00
parent 316093bf1a
commit 93b7ded1c6
No known key found for this signature in database
GPG Key ID: 09745AFF9D63C79B
3 changed files with 52 additions and 2 deletions

7
go.mod
View File

@ -1,8 +1,15 @@
module github.com/drone/drone-template-lib module github.com/drone/drone-template-lib
require ( require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
github.com/Masterminds/sprig v2.18.0+incompatible
github.com/aymerick/raymond v2.0.2+incompatible github.com/aymerick/raymond v2.0.2+incompatible
github.com/bouk/monkey v1.0.0 github.com/bouk/monkey v1.0.0
github.com/google/uuid v1.1.0 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/pkg/errors v0.8.0 github.com/pkg/errors v0.8.0
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643 github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect
) )

16
go.sum
View File

@ -1,6 +1,22 @@
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsLuDE6FEcNbWEpw+lI=
github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0=
github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/bouk/monkey v1.0.0 h1:k6z8fLlPhETfn5l9rlWVE7Q6B23DoaqosTdArvNQRdc=
github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE= github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE=
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643 h1:ii/sHfgFMByozryLeiDmn1ClZ/Pena4NgpJ4P7UuX9o=
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0= github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

View File

@ -23,6 +23,7 @@ import (
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/Masterminds/sprig"
"github.com/aymerick/raymond" "github.com/aymerick/raymond"
) )
@ -38,13 +39,19 @@ var (
"uppercasefirst": uppercaseFirst, "uppercasefirst": uppercaseFirst,
"uppercase": strings.ToUpper, "uppercase": strings.ToUpper,
"lowercase": strings.ToLower, "lowercase": strings.ToLower,
"trim": strings.TrimSpace,
"title": strings.Title,
"regexReplace": regexReplace, "regexReplace": regexReplace,
} }
) )
func init() { func init() {
for name, function := range sprig.GenericFuncMap() {
if invalidHelper(name) {
continue
}
funcs[name] = function
}
raymond.RegisterHelpers(funcs) raymond.RegisterHelpers(funcs)
} }
@ -124,3 +131,23 @@ func regexReplace(pattern string, input string, replacement string) string {
re := regexp.MustCompile(pattern) re := regexp.MustCompile(pattern)
return re.ReplaceAllString(input, replacement) return re.ReplaceAllString(input, replacement)
} }
func invalidHelper(name string) bool {
invalids := []string{
"buildCustomCert",
"fail",
"genSelfSignedCert",
"genSignedCert",
"genCA",
"semver",
"semverCompare",
}
for _, invalid := range invalids {
if name == invalid {
return true
}
}
return false
}