Skip to content

Commit

Permalink
chore: return to sprig (evcc-io#16482)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Oct 4, 2024
1 parent 47c73a7 commit 84f5c56
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 25 deletions.
4 changes: 2 additions & 2 deletions cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
_ "embed"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/evcc-io/evcc/util/templates"
"github.com/go-sprout/sprout/sprigin"
)

type device struct {
Expand Down Expand Up @@ -116,7 +116,7 @@ var configTmpl string

// RenderConfiguration creates a yaml configuration
func (c *Configure) RenderConfiguration() ([]byte, error) {
tmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(configTmpl)
tmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(configTmpl)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"path/filepath"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/evcc-io/evcc/core"
"github.com/evcc-io/evcc/server"
"github.com/evcc-io/evcc/util/config"
"github.com/go-sprout/sprout/sprigin"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -70,7 +70,7 @@ func runDump(cmd *cobra.Command, args []string) {

tmpl := template.Must(
template.New("dump").
Funcs(sprigin.FuncMap()).
Funcs(sprig.FuncMap()).
Parse(dumpTmpl))

out := new(bytes.Buffer)
Expand Down
4 changes: 2 additions & 2 deletions cmd/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/evcc-io/evcc/server/eebus"
"github.com/go-sprout/sprout/sprigin"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func generateEEBUSCert() {
log.FATAL.Fatal("could not process generated certificate", err)
}

t := template.Must(template.New("out").Funcs(sprigin.FuncMap()).Parse(tmpl))
t := template.Must(template.New("out").Funcs(sprig.FuncMap()).Parse(tmpl))
if err := t.Execute(os.Stdout, map[string]interface{}{
"public": pubKey,
"private": privKey,
Expand Down
4 changes: 2 additions & 2 deletions cmd/tools/decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strings"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/evcc-io/evcc/api"
"github.com/go-sprout/sprout/sprigin"
combinations "github.com/mxschmitt/golang-combinations"
"github.com/samber/lo"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -74,7 +74,7 @@ func generate(out io.Writer, packageName, functionName, baseType string, dynamic
types := make(map[string]typeStruct, len(dynamicTypes))
combos := make([]string, 0)

tmpl, err := template.New("gen").Funcs(sprigin.FuncMap()).Funcs(template.FuncMap{
tmpl, err := template.New("gen").Funcs(sprig.FuncMap()).Funcs(template.FuncMap{
// contains checks if slice contains string
"contains": slices.Contains[[]string, string],
// ordered returns a slice of typeStructs ordered by dynamicType
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
dario.cat/mergo v1.0.1
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/BurntSushi/toml v1.4.0
github.com/Masterminds/sprig/v3 v3.3.0
github.com/PuerkitoBio/goquery v1.10.0
github.com/andig/go-powerwall v0.2.1-0.20230808194509-dd70cdb6e140
github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b
Expand Down Expand Up @@ -34,7 +35,6 @@ require (
github.com/glebarez/sqlite v1.11.0
github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1
github.com/go-playground/validator/v10 v10.22.1
github.com/go-sprout/sprout v0.6.0
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/go-viper/mapstructure/v2 v2.2.1
github.com/godbus/dbus/v5 v5.1.0
Expand Down Expand Up @@ -109,7 +109,8 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/ahmetb/go-linq/v3 v3.2.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
Expand Down Expand Up @@ -140,6 +141,7 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grid-x/serial v0.0.0-20211107191517-583c7356b3aa // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf // indirect
github.com/insomniacslk/xjson v0.0.0-20240821125711-1236daaf6808 // indirect
Expand Down Expand Up @@ -177,6 +179,7 @@ require (
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbavY5Wv4=
Expand Down Expand Up @@ -200,8 +204,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sprout/sprout v0.6.0 h1:YIcSYNKjFFMORcjts5/N6S0toNcJiX1cbXi619qVjA0=
github.com/go-sprout/sprout v0.6.0/go.mod h1:P6ETppcGn1BR0HZ8r+660aP2hJH7xiamIGiWjA+AE4o=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
Expand Down Expand Up @@ -316,6 +318,8 @@ github.com/hasura/go-graphql-client v0.13.0/go.mod h1:17qYcHgGSensF/wMAHKUhtMYaR
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down Expand Up @@ -587,6 +591,8 @@ github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/simonvetter/modbus v1.6.0 h1:RDHJevtc7LDIVoHAbhDun8fy+QwnGe+ZU+sLm9ZZzjc=
github.com/simonvetter/modbus v1.6.0/go.mod h1:hh90ZaTaPLcK2REj6/fpTbiV0J6S7GWmd8q+GVRObPw=
Expand Down
6 changes: 3 additions & 3 deletions push/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"strings"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/util"
"github.com/go-sprout/sprout/sprigin"
)

// Event is a notification event
Expand Down Expand Up @@ -38,10 +38,10 @@ type Hub struct {
func NewHub(cc map[string]EventTemplateConfig, vv Vehicles, cache *util.Cache) (*Hub, error) {
// instantiate all event templates
for k, v := range cc {
if _, err := template.New("out").Funcs(sprigin.FuncMap()).Parse(v.Title); err != nil {
if _, err := template.New("out").Funcs(sprig.FuncMap()).Parse(v.Title); err != nil {
return nil, fmt.Errorf("invalid event title: %s (%w)", k, err)
}
if _, err := template.New("out").Funcs(sprigin.FuncMap()).Parse(v.Msg); err != nil {
if _, err := template.New("out").Funcs(sprig.FuncMap()).Parse(v.Msg); err != nil {
return nil, fmt.Errorf("invalid event message: %s (%w)", k, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions util/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/go-sprout/sprout/sprigin"
"github.com/Masterminds/sprig/v3"
"github.com/samber/lo"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func FormatValue(format string, val interface{}) string {
func ReplaceFormatted(s string, kv map[string]interface{}) (string, error) {
// Enhanced golang template logic
tpl, err := template.New("base").
Funcs(sprigin.FuncMap()).
Funcs(sprig.FuncMap()).
Funcs(map[string]any{
"timeRound": timeRound,
}).Parse(s)
Expand Down
4 changes: 2 additions & 2 deletions util/templates/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout/sprigin"
"github.com/Masterminds/sprig/v3"
)

//go:embed documentation.tpl
Expand Down Expand Up @@ -45,7 +45,7 @@ func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, er
var modbusRender string
if modbusChoices := t.ModbusChoices(); len(modbusChoices) > 0 {
if i, _ := t.ParamByName(ParamModbus); i > -1 {
modbusTmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(documentationModbusTmpl)
modbusTmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(documentationModbusTmpl)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions util/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout/sprigin"
"github.com/Masterminds/sprig/v3"
)

// Template describes is a proxy device for use with cli and automated testing
Expand Down Expand Up @@ -207,7 +207,7 @@ var proxyTmpl string

// RenderProxyWithValues renders the proxy template
func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang string) ([]byte, error) {
tmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(proxyTmpl)
tmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(proxyTmpl)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions util/templates/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout/sprigin"
"github.com/Masterminds/sprig/v3"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -59,5 +59,5 @@ func FuncMap(tmpl *template.Template) *template.Template {
"urlEncode": url.QueryEscape,
}

return tmpl.Funcs(sprigin.FuncMap()).Funcs(funcMap)
return tmpl.Funcs(sprig.FuncMap()).Funcs(funcMap)
}

0 comments on commit 84f5c56

Please sign in to comment.