Skip to content

Commit

Permalink
Add slim-sprig functions to template language
Browse files Browse the repository at this point in the history
slim-sprig is a lightweight library containing a number of useful helper
functions which are useful to use in go templates. Include it in debos
so we can use the functions in recipes.

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc authored and sjoerdsimons committed Dec 30, 2023
1 parent 1a1a610 commit 0a13528
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion actions/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ Comments are allowed and should be prefixed with '#' symbol.
property2: {{$Var}}
The following custom template functions are available
The following custom template functions are available:
- sector: Returns the argument * 512 (convential sector size) e.g. `{{ sector 64 }}`
- escape: Shell escape the argument `{{ escape $var }}`
- functions from [slim-sprig](https://go-task.github.io/slim-sprig/)
Mandatory properties for recipe:
Expand Down Expand Up @@ -81,6 +82,7 @@ import (
"github.com/go-debos/debos"
"gopkg.in/yaml.v2"
"github.com/alessio/shellescape"
"github.com/go-task/slim-sprig/v3"
"path"
"text/template"
"log"
Expand Down Expand Up @@ -246,6 +248,9 @@ func (r *Recipe) Parse(file string, printRecipe bool, dump bool, templateVars ..
}
t.Funcs(funcs)

/* Add slim-sprig functions to template language */
t.Funcs(sprig.FuncMap())

if _, err := t.ParseFiles(file); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ require (
github.com/alessio/shellescape v1.4.2
github.com/docker/go-units v0.5.0
github.com/go-debos/fakemachine v0.0.7
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/uuid v1.4.0
github.com/jessevdk/go-flags v1.5.0
github.com/sjoerdsimons/ostree-go v0.0.0-20201014091107-8fae757256f8
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
gopkg.in/freddierice/go-losetup.v1 v1.0.0-20170407175016-fc9adea44124
gopkg.in/yaml.v2 v2.4.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/go-debos/fakemachine v0.0.7-0.20231110164520-5b4b7a21f3f6 h1:SEK7MCa4
github.com/go-debos/fakemachine v0.0.7-0.20231110164520-5b4b7a21f3f6/go.mod h1:FJxCgej/pEl7zHZ4xUrVncvjAQ2oMyQ/zQcMKpjST2o=
github.com/go-debos/fakemachine v0.0.7 h1:TyAnZZvlfyWSzT93gMNgMfHijL9guVoNt40IaHV/Xuk=
github.com/go-debos/fakemachine v0.0.7/go.mod h1:FJxCgej/pEl7zHZ4xUrVncvjAQ2oMyQ/zQcMKpjST2o=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
Expand All @@ -29,6 +31,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/surma/gocpio v1.1.0 h1:RUWT+VqJ8GSodSv7Oh5xjIxy7r24CV1YvothHFfPxcQ=
github.com/surma/gocpio v1.1.0/go.mod h1:zaLNaN+EDnfSnNdWPJJf9OZxWF817w5dt8JNzF9LCVI=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
Expand Down

0 comments on commit 0a13528

Please sign in to comment.